Java HashMap.entrySet()
Syntax
HashMap.entrySet() has the following syntax.
public Set <Map.Entry <K, V>> entrySet()
Example
In the following code shows how to use HashMap.entrySet() method.
/*from w ww .j a va 2 s. c om*/
import java.util.HashMap;
import java.util.Set;
public class Main {
public static void main(String args[]) {
HashMap<Integer, String> newmap = new HashMap<Integer, String>();
newmap.put(1, "tutorials");
newmap.put(2, "from");
newmap.put(3, "java2s.com");
// create set view for the map
Set set=newmap.entrySet();
// check set values
System.out.println("Set values: " + set);
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »