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:
- For Loop in Java
- C# For Loop Example
- Linux Bash Shell: 10 For Loop Examples
- Learn PHP For Loops With Examples
- Oracle FOR LOOP SELECT Statement Example