Java 8 single line forEach for looping through Collection

Java 8 introduced a new forEach method for Iterables ( such as List ) as well as for Map.
Lets see an example of looping through List and Map using forEach ( which uses Lambda Expression ).

Example : forEach + Lambda Expression = Loop through Collection

Employee.java

OUTPUT

Looping result for List :
Employee Name : Naveen , Salary : 1000
Employee Name : Hari , Salary : 2000
Employee Name : Raju , Salary : 9000

Looping result for Map :
Name : Hari , Salary : 2000
Name : Naveen , Salary : 1000
Name : Raju , Salary : 9000

 

Author of CodeForEach.com . Loves coding and related technologies.
 

www.000webhost.com