Traversing the map
Why traversing the map is tough ...? Oooh.... Is it really tough...? I am gonna tell you a trick... Just remember...😁 Map can't be traversed directly... First map will be converted to the set ... Then set can be traversed using Foreach ,for ,while....etc So the thing is how will we convert it to set... And which set... W a ys... ----------------- Source : https://www.google.com/amp/s/www.geeksforgeeks.org/iterate-map-java/amp/ U sin g for ea c h an d e ntry Set() ------------------- For(Map.Entry< Integer,Integer> entry : map.entrySet()) { System.out.println("Key = " +entry.getKey() +", Value= "+ entry.getValue()); } Explanation : Here... In line one... In map.entrySet()... EntrySet() is a method returns the set view of the map...when we are applying it on map I.e. map.entrySet() The syntax of entrySet() is ... Public Set<Map.Entry<K,V>> entrySet() ...