Skip to main content


Showing posts from December, 2019

Iterate HashMap in Java

How to Iterate hashmap in Java In this article, we are going to see different ways to iterate hashmap in java. While using hashmap, we must know how to iterate hashmap in java as it is very common instance and we found ourselves again and again that we need to iterate hashmap. In this post, we will also see how java 8 makes the process of iteration over the hashmap is very easy. Below, we are creating a HashMap and use this hashmap throughout this post to see the different ways of iteration of hashmap in java: // Map to store Roll no. of students with their name Map<Integer, String> hashMap = new HashMap<>(); hashMap.put(101, "Shubham"); hashMap.put(102, "Jatin"); hashMap.put(103, "Nikhil"); hashMap.put(104, "Priyanka"); hashMap.put(105, "Kajal"); How to iterate HashMap in Java using forEach() method In this section, we will see the forEach() method to iterate hashmap in java, java provides for