HashTable boolean equals(Object o) Method Example Program


Compares the specified Object with this Map for equality, as per the definition in the Map interface.

Program

package com.candidjava;

import java.util.Hashtable;

/**
 * @author: Hari Haran
 * @discription: The equals(Object o) method is used to compare the specified
 *               Object with this Map for equality.
 */

public class HashTableEquals {
	public static void main(String[] args) {

		Hashtable<Integer, String> ht1 = new Hashtable<Integer, String>();
		Hashtable<Integer, String> ht2 = new Hashtable<Integer, String>();

		ht1.put(1, "Anand");
		ht1.put(2, "Hari Haran");
		ht1.put(3, "Kamal");
		ht1.put(4, "Karthikeyan");
		ht1.put(5, "Mohan");
		ht1.put(6, "Vinoth");
		ht1.put(7, "Hari Haran");

		ht2.put(1, "Anand");
		ht2.put(2, "Hari Haran");
		ht2.put(3, "Kamal");
		ht2.put(4, "Karthikeyan");
		ht2.put(5, "Mohan");
		ht2.put(6, "Vinoth");
		ht2.put(7, "Hari Haran");

		boolean isequal = ht1.equals(ht2);

		System.out.println("Are two tables equal:" + isequal);
	}
}

Output

Are two tables equal:true

Explanation

public boolean equals(Object o)
Compares the specified Object with this Map for equality, as per the definition in the Map interface.
Specified by:
equals in interface Map<K,V>
Overrides:
equals in class Object
Parameters:
o - object to be compared for equality with this hashtable
Returns:
true if the specified Object is equal to this Map


Related Post

Comments


©candidjava.com