首页 > 代码库 > Java review--hashMap

Java review--hashMap

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());

 效果图:

技术分享

keySet();键集合

entrySet():键值对

values():值集合

 

 

	
		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}

 

Java review--hashMap