Hashtable equals Example


Hashtable class equals method example.public boolean equals(Object o) Compares the specified Object with this Map for equality, as per the definition in the Map interface.

Here is the code

/**
 * @ # Equals.java
 * A class repersenting use to equals method 
 * of HashMap class in java.util package
 * version 19 May 2008
 * author Rose India 
 */
import java.util.*;

public class Equals {

    public static void main(String args[]) {
        Hashtable table = new Hashtable();
        Hashtable table1 = new Hashtable();

        //Put value into the table
        table.put(1"A");
        table.put(2"B");
        table.put(3"C");
        table.put(4"D");
        System.out.println("table :" + table);

        //Put value into the table1
        table1.put(1"A");
        table1.put(2"B");
        table1.put(3"C");
        table1.put(4"D");
        System.out.println("table1 :" + table1);

        //Compares the specified Object with Map for equality
        System.out.println("table and table1 are equals" + table.equals(table1));
    }
}

Output
table :{4=D, 3=C, 2=B, 1=A}
table1 :{4=D, 3=C, 2=B, 1=A}
table and table1 are equal true

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US