当前位置:网站首页>Groovy之范围
Groovy之范围
2022-06-23 11:03:00 【悠然予夏】
1、range的定义方式
Groovy中的range定义是前后各一个数字,然后中间用..进行分隔,表示一个范围
def range = 1..10 // 表示1~102、Groovy中的常用方法
Range 继承了Java中的的List接口,因此groovy中对列表操作的方法,对range依然适用
2.1、获取值
range[0]2.2、contains方法
查看范围中是否包含某个元素,返回值是布尔类型
range.contains(10) // 布尔类型2.3、from方法获取范围上边界
range.from2.4、to方法获取范围的下边界
range.to3、范围遍历
range.each { // groovy方式,推荐使用
println it
}
for (i in range) { // Java方式
println i
}4、范围在switch case中的使用
def result = getGrade(99)
println result
def getGrade(Number number) {
def result
switch (number) {
case 0..<60:
result = '不及格'
break
case 60..<70:
result = '及格'
break
case 70..<80:
result = '良好'
break
case 80..100:
result = '优秀'
break
}
return result // return可以省略
}边栏推荐
- STM32F103ZET6单片机双串口互发程序设计与实现
- PHP regular expression
- [use of Matlab graphical user interface controls]
- Experience of using thread pool in project
- Stm32f1 and stm32subeide programming example - infrared tracking sensor driver
- The simplest DIY pca9685 steering gear control program based on the integration of upper and lower computers of C # and 51 single chip microcomputer
- Noi OJ 1.3 04: C language with remainder Division
- Unity technical manual - lifecycle lifetimebyemitterspeed - color in the cycle coloroverlifetime- speed color colorbyspeed
- Whether Changan Lumin has the ability to become a broken product in the micro electricity market
- Design and implementation of esp32-cam wireless monitoring intelligent gateway
猜你喜欢

The simplest DIY pca9685 steering gear control program based on the integration of upper and lower computers of C # and 51 single chip microcomputer

Simplest DIY steel patriot machine gun controller based on Bluetooth, 51 MCU and steering gear

Stockage d'images - référence

为什么poll/select在open时要使用非阻塞NONBLOCK

Installation and use of binabsinspector, an open source binary file static vulnerability analysis tool

Simplest DIY remote control computer system based on STM32 ② (wireless remote control + key control)

“互联网+”大赛命题火热对接中 | 一图读懂百度38道命题

圖片存儲--引用

Picture storage -- Reference

ESP32-CAM、ESP8266、WIFI、蓝牙、单片机、热点创建嵌入式DNS服务器
随机推荐
Analysis of LinkedList source code
最简单DIY基于C#和51单片机上下位机一体化的PCA9685舵机控制程序
证券开户网上安全度高吗
如何用 Redis 实现一个分布式锁
最简单DIY基于STM32F407探索者开发板的MPU6050陀螺仪姿态控制舵机程序
NOI OJ 1.2 整型与布尔型的转换 C语言
Noi OJ 1.4 01: positive and negative C language
A child process is created in the program, and then the parent and child processes run independently. The parent process reads lowercase letters on the standard input device and writes them to the pip
argmax函数笔记-全是细节
NOI OJ 1.2 整数数据类型存储空间大小
MySQL-01. Summary of database optimization and explain field knowledge in work
Simplest DIY steel patriot machine gun controller based on Bluetooth, 51 MCU and steering gear
Is the online security of securities account opening high
韦东山设备信息查询例程学习
Why does the pointer not change the corresponding value as a formal parameter
Step by step introduction to sqlsugar based development framework (9) -- Realizing field permission control with WinForm control
The simplest DIY serial port Bluetooth hardware implementation scheme
Flush recommended? Is it safe to open a mobile account?
PHP regular expression
Weidongshan equipment information query routine learning