/**
* @author lautturi.com
* example : illustrate the entrySet() method in Java
*/
import java.util.*;
public class Lau {
public static void main(String[] args) {
// Creating an empty HashMap
HashMap<Integer, String> hash_map = new HashMap<Integer, String>();
// Mapping string values to int keys
hash_map.put(1, "Hello");
hash_map.put(3, "Lautturi");
hash_map.put(4, "Java");
hash_map.put(5, "World");
hash_map.put(7, "!");
// Displaying the HashMap
System.out.println("Initial Mappings are: " + hash_map);
// Using entrySet() to get the set view
System.out.println("The set is: " + hash_map.entrySet());
}
}
output
Initial Mappings are: {1=Hello, 3=Lautturi, 4=Java, 5=World, 7=!}
The set is: [1=Hello, 3=Lautturi, 4=Java, 5=World, 7=!]