码迷,mamicode.com
首页 > 其他好文 > 详细

Groovy学习笔记-布尔求值

时间:2017-07-27 16:00:39      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:学习笔记   groov   color   学习   output   布尔   集合   logs   判断   

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

 

Groovy学习笔记-布尔求值

标签:学习笔记   groov   color   学习   output   布尔   集合   logs   判断   

原文地址:http://www.cnblogs.com/ironcrow/p/7244895.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!