Java provides a new method forEach() to iterate the elements. It is defined in the Iterable and Stream interface.
It is a default method defined in the Iterable interface. Collection classes which extend Iterable interface can use the forEach loop to iterate elements. – add in jdk1.8

This method takes a single parameter which is a functional interface. So, you can pass a lambda expression as an argument.

import java.util.ArrayList; 
import java.util.List; 
public class ForEach

{ 
public static void main(String[] args)     
 {  
  List a = new ArrayList(); 
  a.add("DOG");
  a.add("CAT");
  a.add("TIGER"); 
  a.add("ELEPHANT");
  a.add("COW"); 
  System.out.println("------------Iterating by passing lambda expression--------------"); 
  a.forEach(n -> System.out.println(n));         
  System.out.println("------------Iterating by passing method reference---------------");          
a.forEach(System.out::println);   
        System.out.println("------------Iterating by passing lambda expression--------------"); 
 a.stream().forEachOrdered(n -> System.out.println(n)); 
       System.out.println("------------Iterating by passing method reference---------------"); 
 a.stream().forEachOrdered(System.out::println); 
 } 
 }  

OUTPUT

------------Iterating bypassing lambda expression--------------DOG
CAT
TIGER
ELEPHANT
COW
------------Iterating bypassing method reference---------------
DOG
CAT
TIGER
ELEPHANT
COW
------------Iterating bypassing lambda expression--------------
DOG
CAT
TIGER
ELEPHANT
COW
------------Iterating bypassing method reference---------------
DOG
CAT
TIGER
ELEPHANT
COW
Normal way to loop a Map
	Map items = new HashMap<>();
	items.put("A", 10);
	items.put("B", 20);
	items.put("C", 30);
	items.put("D", 40);
	items.put("E", 50);
	items.put("F", 60);

	for (Map.Entry entry : items.entrySet()) {
		System.out.println("Item : " + entry.getKey() + " Count : " + entry.getValue());
	}

In Java 8, you can loop a Map with forEach + lambda expression
Map items = new HashMap<>();
	items.put("A", 10);
	items.put("B", 20);
	items.put("C", 30);
	items.put("D", 40);
	items.put("E", 50);
	items.put("F", 60);
	
	items.forEach((k,v)->System.out.println("Item : " + k + " Count : " + v));
	
	items.forEach((k,v)->{
		System.out.println("Item : " + k + " Count : " + v);
		if("E".equals(k)){
			System.out.println("Hello E");
		}
	});
Normal for-loop to loop a List
	List items = new ArrayList<>();
	items.add("A");
	items.add("B");
	items.add("C");
	items.add("D");
	items.add("E");

	for(String item : items){
		System.out.println(item);
	}
In Java 8, you can loop a List with forEach + lambda expression or method reference.
	List items = new ArrayList<>();
	items.add("A");
	items.add("B");
	items.add("C");
	items.add("D");
	items.add("E");

	//lambda
	//Output : A,B,C,D,E
	items.forEach(item->System.out.println(item));
		
	//Output : C
	items.forEach(item->{
		if("C".equals(item)){
			System.out.println(item);
		}
	});
		
	//method reference
	//Output : A,B,C,D,E
	items.forEach(System.out::println);
	
	//Stream and filter
	//Output : B
	items.stream()
		.filter(s->s.contains("B"))
		.forEach(System.out::println);