IdentityHashMap equals Example

IdentityHashMap class equals example. This example shows you how to use equals method.


IdentityHashMap class equals example.ublic boolean equals(Object o) Compares the specified object with this map for equality. Returns true if the given object is also a map and the two maps represent identical object-reference mappings. More formally, this map is equal to another map m if and only if this.entrySet().equals(m.entrySet()).

Here is the code

/**
 * @ # EntrySet.java
 * A class repersenting use to entrySet method 
 * of IdentityHashMap class in java.util package
 * version 26 May 2008
 * author Rose India 
 */
import java.util.*;

public class Equals {

    public static void main(String args[]) {
        IdentityHashMap map = new IdentityHashMap();
        IdentityHashMap map1 = new IdentityHashMap();
        //Add the mapping into the map 
        map.put(1"A");
        map.put(2"A");
        map.put(3"B");

        //Add the mapping into the map1
        map1.put(1"A");
        map1.put(2"A");
        map1.put(3"B");

        System.out.println(map.equals(map1));
    }
}

Output
true

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

HOME | COPYRIGHT | CONTACT US