Home » Core Java » Java8-ForEach


In this post we are going to code forEach() and forEachOrdered() examples. forEach() method is used to iterate over a collection like List,Set,Map etc or a stream.forEachOrdered() method process the elements in the order the elements are added to collection.

Syntax ::

Program ::
In the below Program I have used three methods to use forEach() over List,Set and Map.I have used the same method to show forEachOrdered() on List and Set using stream.

Output ::

Leave a comment

Your email address will not be published. Required fields are marked *

thirteen + 2 =