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

[Groovy] Array and ArrayList

时间:2015-06-16 16:26:08      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

Array:

def x = new String[5]
x[0] = "India"
x[1] = "USA"
x[2] = "Korea"
x[3] = "Japan"
x[4] = "China"

log.info "Size of list is " + x.size()
log.info "The first item in list is : "+x[0]
for(String item:x){
	log.info item
}

 Result :

Tue Jun 16 14:50:08 CST 2015:INFO:Size of list is 5
Tue Jun 16 14:50:08 CST 2015:INFO:The first item in list is : India
Tue Jun 16 14:50:08 CST 2015:INFO:India
Tue Jun 16 14:50:08 CST 2015:INFO:USA
Tue Jun 16 14:50:08 CST 2015:INFO:Korea
Tue Jun 16 14:50:08 CST 2015:INFO:Japan
Tue Jun 16 14:50:08 CST 2015:INFO:China

ArrayList :

ArrayList list = new ArrayList();
list.add("India")
list.add("USA")
list.add("UK")
list.add("China")

log.info "Size of list is "+list.size()
list.add("Korea")

log.info "Size of list is "+list.size()
log.info "The first item in list is : " + list.get(0)

for(String item:list){
	log.info item
}

 

 Result:

Tue Jun 16 14:57:43 CST 2015:INFO:Size of list is 4
Tue Jun 16 14:57:43 CST 2015:INFO:Size of list is 5
Tue Jun 16 14:57:43 CST 2015:INFO:The first item in list is : India
Tue Jun 16 14:57:43 CST 2015:INFO:India
Tue Jun 16 14:57:43 CST 2015:INFO:USA
Tue Jun 16 14:57:43 CST 2015:INFO:UK
Tue Jun 16 14:57:43 CST 2015:INFO:China
Tue Jun 16 14:57:43 CST 2015:INFO:Korea

[Groovy] Array and ArrayList

标签:

原文地址:http://www.cnblogs.com/MasterMonkInTemple/p/4580805.html

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