Map<String, String> map = new HashMap<String, String>();
map.put("杨过", "小龙女");
map.put("郭靖", "黄蓉");
map.put("梁山伯", "祝英台");
map.put("牛郎", "织女");
Set<String> set = map.keySet();
for (String str : set) {
System.out.println(str);
}
System.out.println("---------");
Collection<String> con = map.values();
for (String str : con) {
System.out.println(str);
}
System.out.println("---------");
System.out.println(map.get("郭靖"));
System.out.println(map.get("牛郎"));
System.out.println(map.get("田野"));
System.out.println("---------");
Set<String> husbandSet = map.keySet();
for (String husband : husbandSet) {
String wife = map.get(husband);
System.out.println(husband + "***" + wife);
}
|
|