In this example, We will show you how to get the mapping of keys and values of the HashMap object in java.
Set view of mapping of java HashMap Example
In this example, We will show you how to get the mapping of keys and values of the HashMap object in java. To get a mapping of keys and values of HashMap object we use the entrySet() method of HashMap Class. This method returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa.
Example:- EntrySetHashMap.java
package devmanuals.com; import java.util.*; public class EntrySetHashMap { public static void main(String args[]) { HashMap hm = new HashMap(); hm.put(1, "Gyan"); hm.put(2, "Ankit"); hm.put(3, "Arun"); hm.put(4, "Anand"); hm.put(5, "Ram"); SetOutput:-> set = hm.entrySet(); for (Map.Entry me : set) { System.out.print(me.getKey() + ": "); System.out.println(me.getValue()); } } }
1 : Gyan 2 : Ankit 3 : Arun 4 : Anand 5 : Ram |
Download This Code.
[ 0 ] Comments