| 16 | System.out.println(map.keySet()); |
| 17 | } |
| 18 | public static |
| 19 | void test(Map<Integer,String> map) { |
| 20 | System.out.println( |
| 21 | map.getClass().getSimpleName()); |
| 22 | map.putAll(new CountMap(25)); |
| 23 | // Map has 'Set' behavior for keys: |
| 24 | map.putAll(new CountMap(25)); |
| 25 | printKeys(map); |
| 26 | // Producing a Collection of the values: |
| 27 | System.out.print("Values: "); |
| 28 | System.out.println(map.values()); |
| 29 | System.out.println(map); |
| 30 | System.out.println("map.containsKey(11): " + |
| 31 | map.containsKey(11)); |
| 32 | System.out.println( |
| 33 | "map.get(11): " + map.get(11)); |
| 34 | System.out.println("map.containsValue(\"F0\"): " |
| 35 | + map.containsValue("F0")); |
| 36 | Integer key = map.keySet().iterator().next(); |
| 37 | System.out.println("First key in map: " + key); |
| 38 | map.remove(key); |
| 39 | printKeys(map); |
| 40 | map.clear(); |
| 41 | System.out.println( |
| 42 | "map.isEmpty(): " + map.isEmpty()); |
| 43 | map.putAll(new CountMap(25)); |
| 44 | // Operations on the Set change the Map: |
| 45 | map.keySet().removeAll(map.keySet()); |
| 46 | System.out.println( |
| 47 | "map.isEmpty(): " + map.isEmpty()); |
| 48 | } |
| 49 | public static void main(String[] args) { |
| 50 | test(new HashMap<>()); |
| 51 | test(new TreeMap<>()); |