import java.util.HashMap; public class Main { public static void main(String[] args) { // Create two HashMaps HashMapmap1 = new HashMap<>(); map1.put("A", 1); map1.put("B", 2); map1.put("C", 3); HashMap map2 = new HashMap<>(); map2.put("A", 1); map2.put("B", 2); map2.put("C", 3); // Compare the two HashMaps for equality boolean isEqual = map1.equals(map2); // Print the result System.out.println(isEqual); // true } }
import java.util.HashMap; public class Main { public static void main(String[] args) { // Create a HashMap HashMapIn this example, we create a HashMap and add some key-value pairs to it. Then we use the equals() method to compare the HashMap with a String object. Since the types are different, the method returns false. The HashMap class is part of the java.util package library.map = new HashMap<>(); map.put("A", 1); map.put("B", 2); map.put("C", 3); // Compare the HashMap with a String (will return false) boolean isEqual = map.equals("ABC"); // Print the result System.out.println(isEqual); // false } }