Groovy For Loop Example (Loop on ArrayList)

Groovy For Loop Example (Loop on ArrayList)

  • Groovy
  • 1 min read

How to create for loop on ArrayList in Groovy? Check the below example:

Groovy - For Loop on List Example

The below Groovy code will create a list object as ArrayList() and will add three elements to it. Then will loop through the list and print on the screen:

List list = new ArrayList();
list.add("first");
list.add("second");
list.add("third");
for (String item : list) {
   System.out.println(item)
}

Output:

$groovy main.groovy
first
second
third

See also: