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.S Ize () Log.info "The first item in list is:" +x[0]for (String item:x) {Log.info Item}
Result:
Tue June 14:50:08 CST 2015:info:size of list is 5
Tue June 14:50:08 CST 2015:info:the first item in list Is:india
Tue June 14:50:08 CST 2015:info:india
Tue June 14:50:08 CST 2015:info:usa
Tue June 14:50:08 CST 2015:info:korea
Tue June 14:50:08 CST 2015:info:japan
Tue June 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 are "+list.size () log.info" The first item in list is: "+ lis T.get (0) for (String item:list) {Log.info Item}
Result:
Tue June 14:57:43 CST 2015:info:size of list is 4
Tue June 14:57:43 CST 2015:info:size of list is 5
Tue June 14:57:43 CST 2015:info:the first item in list Is:india
Tue June 14:57:43 CST 2015:info:india
Tue June 14:57:43 CST 2015:info:usa
Tue June 14:57:43 CST 2015:info:uk
Tue June 14:57:43 CST 2015:info:china
Tue June 14:57:43 CST 2015:info:korea
[Groovy] Array and ArrayList