import java.util.HashMap; HashMapmap = new HashMap<>(); map.put("apple", 3); map.put("banana", 2); map.put("orange", 5); System.out.println(map); // Output: {apple=3, banana=2, orange=5}
import java.util.HashMap; HashMapIn both examples, the code imports the java.util package and creates a new instance of the HashMap class. The put() method is then called to add or update key-value pairs. Finally, the contents of the HashMap are printed to the console. Overall, the java.util package provides many useful data structures and utilities for Java developers.map = new HashMap<>(); map.put("apple", 3); map.put("banana", 2); map.put("orange", 5); map.put("apple", 4); System.out.println(map); // Output: {apple=4, banana=2, orange=5}