import java.util.*; public class TestMap { public static void main (String[] args) { Map testMap = new TreeMap(); //Map testMap = new HashMap(); //Map testMap = new LinkedHashMap(); //Map testMap = new Hashtable(); testMap.put("Allen", 1); testMap.put("Jack", 3); testMap.put("Tom", 5); testMap.put("Tom", 7); int curVal = testMap.get("Tom"); System.out.println("Tom = " + curVal); System.out.println("Current Size = " + testMap.size()); testMap.remove("Tom"); boolean checkContainKey = testMap.containsKey("Tom"); System.out.println("Contains Tom ? " + checkContainKey); System.out.println("Tom value = " + testMap.get("Tom")); for (Map.Entry entry : testMap.entrySet()) { System.out.println(entry.getKey() + ": " + entry.getValue()); } System.out.println("Anna: " + testMap.getOrDefault("Anna", 0)); System.out.println("Jack: " + testMap.getOrDefault("Jack", 0)); } }