AbstractMap.equals()
is a method of the AbstractMap
class in Java. The method is used to check if two maps are equal or not.
public boolean equals(Object obj)
The function takes in one parameter:
obj
: An object to be compared with the map.The function returns true
if the maps are equal, and returns false
if the maps are different.
import java.util.*;public class Abstract_Map_Class{public static void main(String[] args){// 2 empty AbstractMap are createdAbstractMap<Integer, String> temp_absMap1 = new TreeMap<Integer, String>();AbstractMap<Integer, String> temp_absMap2 = new TreeMap<Integer, String>();// populating temp_absMap1temp_absMap1.put(1, "Hello");temp_absMap1.put(2, "from");temp_absMap1.put(3, "Educative");// populating temp_absMap2temp_absMap2.put(1, "Hello");temp_absMap2.put(2, "from");temp_absMap2.put(3, "Edpresso");System.out.println("Displaying temp_absMap1 : " + temp_absMap1);System.out.println("Displaying temp_absMap2 : " + temp_absMap2);System.out.println("the result of temp_absMap1.equals(temp_absMap2) is " + temp_absMap1.equals(temp_absMap2));}}