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 : IndiaTue Jun 16 14:50:08 CST 2015:INFO:IndiaTue Jun 16 14:50:08 CST 2015:INFO:USATue Jun 16 14:50:08 CST 2015:INFO:KoreaTue Jun 16 14:50:08 CST 2015:INFO:JapanTue Jun 16 14:50:08 CST 2015:INFO:ChinaArrayList :
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 5Tue Jun 16 14:57:43 CST 2015:INFO:The first item in list is : IndiaTue Jun 16 14:57:43 CST 2015:INFO:IndiaTue Jun 16 14:57:43 CST 2015:INFO:USATue Jun 16 14:57:43 CST 2015:INFO:UKTue Jun 16 14:57:43 CST 2015:INFO:ChinaTue Jun 16 14:57:43 CST 2015:INFO:Korea