Mapmap = new HashMap<>(); map.put("apple", 1); map.put("banana", 2); map.put("orange", 3); int size = map.size(); System.out.println("The size of the map is " + size);
MapThis example creates a LinkedHashMap and adds key-value pairs to it. The size() method is called to determine the size of the map. Package library: java.utilmap = new LinkedHashMap<>(); map.put(1, "John"); map.put(2, "Mary"); map.put(3, "Peter"); int size = map.size(); System.out.println("The size of the map is " + size);