How to iterate List inside another List in groovy

This example shows you how to iterate one list inside another list in Groovy.

We will use the Clouser to multilevel iteration, Below is the example code.

package com.java.connect.groovy

class GroovyListEachExample {
	static void main(args){
		def list1 = ['Window', 'Linux', 'Mac']
		def list2 = [
			'java',
			'C',
			'C++',
			'.Net',
			'PHP',
			'Testing'
		]

		list1.each {platform->
			list2.each {language-> println "Learning $language on $platform OS."  }
			println "----------------------------------"
		}
	}
}

The output of the above example will be as:

Learning java on Window OS.
Learning C on Window OS.
Learning C++ on Window OS.
Learning .Net on Window OS.
Learning PHP on Window OS.
Learning Testing on Window OS.
----------------------------------
Learning java on Linux OS.
Learning C on Linux OS.
Learning C++ on Linux OS.
Learning .Net on Linux OS.
Learning PHP on Linux OS.
Learning Testing on Linux OS.
----------------------------------
Learning java on Mac OS.
Learning C on Mac OS.
Learning C++ on Mac OS.
Learning .Net on Mac OS.
Learning PHP on Mac OS.
Learning Testing on Mac OS.
----------------------------------