Difference between HashMap and IndentityHashMap

It is exactly same as HashMap except the below difference.

  • HashMap uses equals() method to indentify duplicate keys for object’s content comparision.
  • IndentityHashMap uses ‘==’ operator to identify duplicate keys.

Example : 

In this example we are creating HashMap and IndentityHashMap objects and inserting integer values.

 

 Output:

HashMap uses equals method for comparison (i1.equals (i2)).

IndentityHashMap uses == operator for comparison (i3==i4).

Posted in collections and tagged , , .

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">