Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Practical use of IdentityHashMap in Java 6 [duplicate]

Tags:

java

Possible Duplicate:
Use cases for IdentityHashMap

What could be a practical use of the IdentityHashMap introduced in Java 5?

like image 656
Jyotirup Avatar asked Dec 29 '11 12:12

Jyotirup


People also ask

What is the main use of IdentityHashMap?

This class implements the Map interface with a hash table, using reference-equality in place of object-equality when comparing keys (and values). In other words, in an IdentityHashMap, two keys k1 and k2 are considered equal if and only if (k1==k2).

What is difference between HashMap and IdentityHashMap in Java?

HashMap uses object equality to compare the key and values. IdentityHashMap uses reference equality to compare the key and values.

Is identity HashMap is synchronized?

Features of IdentityHashMapIt is not synchronized and must be synchronized externally. Iterators are fail-fast, throw ConcurrentModificationException in an attempt to modify while iterating.

What are IdentityHashMap and WeakHashMap?

The IdentityHashMap, WeakHashMap, and EnumMap all are the classes in java collection that implements the Map interface.


1 Answers

Have a look at the Java Docs :-)

A typical use of this class is topology-preserving object graph transformations, such as serialization or deep-copying. To perform such a transformation, a program must maintain a "node table" that keeps track of all the object references that have already been processed. The node table must not equate distinct objects even if they happen to be equal. Another typical use of this class is to maintain proxy objects. For example, a debugging facility might wish to maintain a proxy object for each object in the program being debugged.

On a side note: it's available since version 1.4, not Java 5 or 6...

like image 156
Matten Avatar answered Oct 19 '22 11:10

Matten