Map map = new HashMap();
map.put("1", "11");
map.put("2", "22");
System.out.println("里面的值有:");
Collection connection = map.values();
Iterator iterator = connection.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next() + "..");
}
System.out.println("里面的键有:");
Set key = map.keySet();
for (String string : key) {
System.out.println(string);
}
System.out.println("里面的键值对是:");
Set> set = map.entrySet();
Iterator> iterator2 = set.iterator();
while (iterator2.hasNext()) {
Map.Entry entry = iterator2.next();
System.out.println("键是:" + entry.getKey() + "值是:" + entry.getValue());
} 以上是三种取值方式,第一种是取出所有的值,第二种是取出所有的键,第三种是取出键值对。