6 ways to iterate or loop a Map in Java

Damith
68.6K views

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

There are multiple ways to iterate or loop a Map in Java.

Using foreach in Java 8

If you using Java 8 this is the easiest way to loop the Map.

Using stream() in Java 8

This is also using in Java 8. If you want to filter some data while looping this is one of best way to do that.

Using entrySet()

Using keySet()

Using iterator through map

This way is more suitable for when you need to remove some data while iterating.

Using iterator through the KeySet

Original post :- http://mydevgeek.com/6-ways-iterate-loop-map-java/

Open Source Your Knowledge: become a Contributor and help others learn. Create New Content