java.util.IdentityHashMap.equals() Method

Advertisements


Description

The equals(Object o) method is used to compare the specified object with this map for equality.

Declaration

Following is the declaration for java.util.IdentityHashMap.equals() method.

public boolean equals(Object o)

Parameters

  • o--This is the object to be compared for equality with this map.

Return Value

The method call returns 'true' if the specified object is equal to this map.

Exception

  • NA

Example

The following example shows the usage of java.util.IdentityHashMap.equals()

package com.tutorialspoint;

import java.util.*;

public class IdentityHashMapDemo {
   public static void main(String args[]) {
      // create 2 identity hash maps
      IdentityHashMap ihmap1 = new IdentityHashMap();
      IdentityHashMap ihmap2 = new IdentityHashMap();
      
      // populate 2 maps
      ihmap1.put(1, "java");
      ihmap1.put(2, "util");
      ihmap1.put(3, "package");
      
      ihmap2.put(1, "java");
      ihmap2.put(2, "awt");
      ihmap2.put(3, "package");
      
      // compare 2 maps
      boolean isequal=ihmap1.equals(ihmap2);

      System.out.println("Is two maps equal: " + isequal);
   }    
}

Let us compile and run the above program, this will produce the following result.

Is two maps equal: false



Advertisements
Advertisements