The equals() method of HashTable is used to check the equality between two HashTable objects. It is available under the java.util package.
HashTable.equals(parameter);
This method takes a single object to compare with any HashTable.
The method returns true if the HashTable is the same as the given object. Otherwise, it returns false.
Let’s have a look at the code.
import java.util.*;class Solution1 {public static void main(String args[]) {// create two hash tablesHashtable<Integer,String> table1 = new Hashtable<Integer,String>();Hashtable<Integer,String> table2 = new Hashtable<Integer,String>();// put values in two tablestable1.put(1, "A");table1.put(2, "B");table1.put(3, "C");table1.put(4, "D");table2.put(1, "A");table2.put(2, "B");table2.put(3, "C");table2.put(4, "D");// display resultSystem.out.println("Are two tables equal:"+table1.equals(table2));}}
java.util.* classes to include the HashSet data structure.table1 and table2table1.table2.table2 is equal to table1 or not, and print the result.