package cn.edu.bjut.chapter6; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; public class MapTester { public static void main(String[] args) { Map id2Names = new HashMap(); id2Names.put("213456", new Name("Albert", "Einstein")); id2Names.put("123456", new Name("Albert", "Einstein")); id2Names.put("321456", new Name("Qiang", "Yang")); id2Names.put("456321", new Name("Qiang", "Yang")); System.out.println(id2Names); System.out.println(id2Names.keySet()); System.out.println(id2Names.values()); Map id2Names2 = new LinkedHashMap(); id2Names2.put("213456", new Name("Albert", "Einstein")); id2Names2.put("123456", new Name("Albert", "Einstein")); id2Names2.put("321456", new Name("Qiang", "Yang")); id2Names2.put("456321", new Name("Qiang", "Yang")); System.out.println(id2Names2); System.out.println(id2Names2.keySet()); System.out.println(id2Names2.values()); for (Map.Entry entry : id2Names.entrySet()) { System.out.println(entry.getKey() + ":" + entry.getValue()); } } }