java.util.HashMap.entrySet() Method
Advertisements
Description
The entrySet() method is used to get a Set view of the mappings contained in this map.
Declaration
Following is the declaration for java.util.HashMap.entrySet() method.
public Set<Map.Entry<K,V>> entrySet()
Parameters
NA
Return Value
The method call returns a set view of the mappings contained in this map.
Exception
NA
Example
The following example shows the usage of java.util.HashMap.entrySet()
package com.tutorialspoint;
import java.util.*;
public class HashMapDemo {
public static void main(String args[]) {
// create hash map
HashMap newmap = new HashMap();
// populate hash map
newmap.put(1, "tutorials");
newmap.put(2, "point");
newmap.put(3, "is best");
// create set view for the map
Set set=newmap.entrySet();
// check set values
System.out.println("Set values: " + set);
}
}
Let us compile and run the above program, this will produce the following result.
Set values: [1=tutorials, 2=point, 3=is best]