Person p1 = new Person(1,"xiaoming");
Person p2 = new Person(2,"xiaozhang");
Map<Integer, Person> map = new HashMap<>();
map.put(1,p1);
map.put(2,p2);
// Map.entrySet() 这个方法返回的是一个Set<Map.Entry<K,V>>,Map.Entry
是Map中的一个接口,他的用途是表示一个映射项(里面有Key和Value),
而Set<Map.Entry<K,V>>表示一个映射项的Set。Map.Entry里有相应的getKey和
getValue方法,即JavaBean,让我们能够从一个项中取出Key和Value。
for (Map.Entry<Integer, Person> a : map.entrySet()) {
System.out.println("键为:" + a.getKey());
System.out.println("值为:" + a.getValue());
}