import java.util.*; import java.lang.*; public class StudentMap { private Map students; public StudentMap() { students = new LinkedHashMap(); populateMap(); } public final void populateMap() { students.put(1, new Student("John", "Smith")); students.put(2, new Student("Stanley", "Peters")); students.put(3, new Student("Edgar", "Bloch")); students.put(4, new Student("Suzan", "Miles")); students.put(5, new Student("Mary", "Poppins")); } public void iterateMapEntries() { Set set = students.entrySet(); Iterator it = set.iterator(); while(it.hasNext()) { System.out.println(it.next().toString()); } } public void iterateMapValues() { Collection col = students.values(); Iterator it = col.iterator(); while(it.hasNext()) { System.out.println(it.next().toString()); } } public void iterateMapKeys() { Set set = students.keySet(); Iterator it = set.iterator(); while(it.hasNext()) { System.out.println(it.next().toString()); } } public static void main(String args[]) { StudentMap stl = new StudentMap(); System.out.println("Map keys are:"); stl.iterateMapKeys(); System.out.println("Map values are:"); stl.iterateMapValues(); System.out.println("Map key-value pairs are:"); stl.iterateMapEntries(); } }