Groovy学习笔记-布尔求值

1.判断字符串为null或空字符串

def str = null
if(str)
println 'str is not null'
else
println 'str is null' str = ''
if(str)
println 'str is not null'
else
println 'str is null' /*output
str is null
str is null
*/

2.集合是否为空或Count ==0

list = null
if(list)
println 'list is not null'
else
println 'list is null' list = []
if(list)
println 'list is not null'
else
println 'list is null' /*output
list is null
list is null
*/

3.集合新增元素

def list = ['aaa'];
list<<'a' println list
上一篇:Go语言基础之13--线程安全及互斥锁和读写锁


下一篇:qrcode生成二维码插件