Java代碼:java
Map aMap =new HashMap<String, String>(); aMap.put("1", "A"); aMap.put("2", "B"); aMap.put("3", "C"); System.out.println(aMap.keySet()); System.out.println(aMap.entrySet()); System.out.println(aMap.values());
效果圖:blog
keySet();鍵集合rem
entrySet():鍵值對class
values():值集合im
Map aMap =new HashMap<String, String>(); aMap.put("1", "A"); aMap.put("2", "B"); aMap.put("3", "C"); //aMap.clear();//移除全部映射關係 Map bMap =new HashMap<String, String>(); bMap.putAll(aMap); System.out.println(aMap.containsValue("d"));//false System.out.println(aMap.keySet());//[1, 2, 3] System.out.println(aMap.entrySet());//[1=A, 2=B, 3=C] System.out.println(aMap.values());//[A, B, C] aMap.remove("2"); System.out.println(aMap);//{1=A, 3=C} System.out.println(aMap.size());//2 aMap.clear(); System.out.println(aMap.isEmpty());//true System.out.println(bMap);//{1=A, 2=B, 3=C}