
States("Tamilnadu", listOf(Places("chennai", electrnoics))))Ĭt.stplaces.forEach ") States("Delhi", listOf(Places("Noida", laptops), Val laptops = listOf("Dell latitude", "dell inspiron","sony","acer","samsung","lenovo","apple") Val electrnoics = listOf("Ups","Inverters","Gadgets","Desktop PCs","Microwave Oven","Fridge","Washing Machine","mobile") Val mn = listOf("January", "February","March","April","May","June","July","August","September","October","November","December") Given below are the examples mentioned: Example #1Ĭode: class States(val stname : String, val stcapital : List)Ĭlass Places(val pname : String, val cities : List) The implicit parameters are enclosing and enforced for the other lambda and anonymous statements.

In array and other list collections, the for and forEach loops are the same when generating the output results from the array or the collection list.

If we use a collection concept like a list, map the datas are passing to the array type and the values are calculated using the index-based format.

It also calls with the other util and packages like collections, files,s, etc.

The forEach loop is one of the iteration loops for but we can call additional functions with the variable using the datatype.It is like a functional approach towards the perform traditional for using the loop paths. We can call forEach() loop method to perform the action on each and every element of the list. The above codes are one of the basic syntaxes for utilizing the forEach() loop in different areas. some conditional statement depends on the requirement. CollectionMethod(input values).forEach(fun(variable:datatype))
