java.util
Class IdentityHashMap<K,V>

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.util.AbstractMap sample code for java.util.AbstractMap definition code for java.util.AbstractMap <K,V>
      extended by java.util.IdentityHashMap<K,V>
All Implemented Interfaces:
Serializable sample code for java.io.Serializable definition code for java.io.Serializable , Cloneable sample code for java.lang.Cloneable definition code for java.lang.Cloneable , Map sample code for java.util.Map definition code for java.util.Map <K,V>

public class IdentityHashMap<K,V>
extends AbstractMap sample code for java.util.AbstractMap definition code for java.util.AbstractMap <K,V>
implements Map sample code for java.util.Map definition code for java.util.Map <K,V>, Serializable sample code for java.io.Serializable definition code for java.io.Serializable , Cloneable sample code for java.lang.Cloneable definition code for java.lang.Cloneable

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). (In normal Map implementations (like HashMap) two keys k1 and k2 are considered equal if and only if (k1==null ? k2==null : k1.equals(k2)).)

This class is not a general-purpose Map implementation! While this class implements the Map interface, it intentionally violates Map's general contract, which mandates the use of the equals method when comparing objects. This class is designed for use only in the rare cases wherein reference-equality semantics are required.

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.

This class provides all of the optional map operations, and permits null values and the null key. This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time.

This class provides constant-time performance for the basic operations (get and put), assuming the system identity hash function (System.identityHashCode(Object) sample code for java.lang.System.identityHashCode(java.lang.Object) definition code for java.lang.System.identityHashCode(java.lang.Object) ) disperses elements properly among the buckets.

This class has one tuning parameter (which affects performance but not semantics): expected maximum size. This parameter is the maximum number of key-value mappings that the map is expected to hold. Internally, this parameter is used to determine the number of buckets initially comprising the hash table. The precise relationship between the expected maximum size and the number of buckets is unspecified.

If the size of the map (the number of key-value mappings) sufficiently exceeds the expected maximum size, the number of buckets is increased Increasing the number of buckets ("rehashing") may be fairly expensive, so it pays to create identity hash maps with a sufficiently large expected maximum size. On the other hand, iteration over collection views requires time proportional to the number of buckets in the hash table, so it pays not to set the expected maximum size too high if you are especially concerned with iteration performance or memory usage.

Note that this implementation is not synchronized. If multiple threads access this map concurrently, and at least one of the threads modifies the map structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more mappings; merely changing the value associated with a key that an instance already contains is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the map. If no such object exists, the map should be "wrapped" using the Collections.synchronizedMap method. This is best done at creation time, to prevent accidental unsynchronized access to the map:

     Map m = Collections.synchronizedMap(new HashMap(...));
 

The iterators returned by all of this class's "collection view methods" are fail-fast: if the map is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove or add methods, the iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.

Note that the fail-fast behavior of an iterator cannot be guaranteed as it is, generally speaking, impossible to make any hard guarantees in the presence of unsynchronized concurrent modification. Fail-fast iterators throw ConcurrentModificationException on a best-effort basis. Therefore, it would be wrong to write a program that depended on this exception for its correctness: fail-fast iterators should be used only to detect bugs.

Implementation note: This is a simple linear-probe hash table, as described for example in texts by Sedgewick and Knuth. The array alternates holding keys and values. (This has better locality for large tables than does using separate arrays.) For many JRE implementations and operation mixes, this class will yield better performance than HashMap sample code for java.util.HashMap definition code for java.util.HashMap (which uses chaining rather than linear-probing).

This class is a member of the Java Collections Framework.

Since:
1.4
See Also:
System.identityHashCode(Object) sample code for java.lang.System.identityHashCode(java.lang.Object) definition code for java.lang.System.identityHashCode(java.lang.Object) , Object.hashCode() sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , Collection sample code for java.util.Collection definition code for java.util.Collection , Map sample code for java.util.Map definition code for java.util.Map , HashMap sample code for java.util.HashMap definition code for java.util.HashMap , TreeMap sample code for java.util.TreeMap definition code for java.util.TreeMap , Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map sample code for java.util.Map definition code for java.util.Map
Map.Entry sample code for java.util.Map.Entry definition code for java.util.Map.Entry <K,V>
 
Constructor Summary
IdentityHashMap sample code for java.util.IdentityHashMap.IdentityHashMap() definition code for java.util.IdentityHashMap.IdentityHashMap() ()
          Constructs a new, empty identity hash map with a default expected maximum size (21).
IdentityHashMap sample code for java.util.IdentityHashMap.IdentityHashMap(int) definition code for java.util.IdentityHashMap.IdentityHashMap(int) (int expectedMaxSize)
          Constructs a new, empty map with the specified expected maximum size.
IdentityHashMap sample code for java.util.IdentityHashMap.IdentityHashMap(java.util.Map) definition code for java.util.IdentityHashMap.IdentityHashMap(java.util.Map) (Map sample code for java.util.Map definition code for java.util.Map <? extends K,? extends V> m)
          Constructs a new identity hash map containing the keys-value mappings in the specified map.
 
Method Summary
 void clear sample code for java.util.IdentityHashMap.clear() definition code for java.util.IdentityHashMap.clear() ()
          Removes all mappings from this map.
 Object sample code for java.lang.Object definition code for java.lang.Object clone sample code for java.util.IdentityHashMap.clone() definition code for java.util.IdentityHashMap.clone() ()
          Returns a shallow copy of this identity hash map: the keys and values themselves are not cloned.
 boolean containsKey sample code for java.util.IdentityHashMap.containsKey(java.lang.Object) definition code for java.util.IdentityHashMap.containsKey(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  key)
          Tests whether the specified object reference is a key in this identity hash map.
 boolean containsValue sample code for java.util.IdentityHashMap.containsValue(java.lang.Object) definition code for java.util.IdentityHashMap.containsValue(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  value)
          Tests whether the specified object reference is a value in this identity hash map.
 Set sample code for java.util.Set definition code for java.util.Set <Map.Entry sample code for java.util.Map.Entry definition code for java.util.Map.Entry <K,V>> entrySet sample code for java.util.IdentityHashMap.entrySet() definition code for java.util.IdentityHashMap.entrySet() ()
          Returns a set view of the mappings contained in this map.
 boolean equals sample code for java.util.IdentityHashMap.equals(java.lang.Object) definition code for java.util.IdentityHashMap.equals(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  o)
          Compares the specified object with this map for equality.
 V get sample code for java.util.IdentityHashMap.get(java.lang.Object) definition code for java.util.IdentityHashMap.get(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  key)
          Returns the value to which the specified key is mapped in this identity hash map, or null if the map contains no mapping for this key.
 int hashCode sample code for java.util.IdentityHashMap.hashCode() definition code for java.util.IdentityHashMap.hashCode() ()
          Returns the hash code value for this map.
 boolean isEmpty sample code for java.util.IdentityHashMap.isEmpty() definition code for java.util.IdentityHashMap.isEmpty() ()
          Returns true if this identity hash map contains no key-value mappings.
 Set sample code for java.util.Set definition code for java.util.Set <K> keySet sample code for java.util.IdentityHashMap.keySet() definition code for java.util.IdentityHashMap.keySet() ()
          Returns an identity-based set view of the keys contained in this map.
 V put sample code for java.util.IdentityHashMap.put(K, V) definition code for java.util.IdentityHashMap.put(K, V) (K key, V value)
          Associates the specified value with the specified key in this identity hash map.
 void putAll sample code for java.util.IdentityHashMap.putAll(java.util.Map) definition code for java.util.IdentityHashMap.putAll(java.util.Map) (Map sample code for java.util.Map definition code for java.util.Map <? extends K,? extends V> t)
          Copies all of the mappings from the specified map to this map These mappings will replace any mappings that this map had for any of the keys currently in the specified map.
 V remove sample code for java.util.IdentityHashMap.remove(java.lang.Object) definition code for java.util.IdentityHashMap.remove(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  key)
          Removes the mapping for this key from this map if present.
 int size sample code for java.util.IdentityHashMap.size() definition code for java.util.IdentityHashMap.size() ()
          Returns the number of key-value mappings in this identity hash map.
 Collection sample code for java.util.Collection definition code for java.util.Collection <V> values sample code for java.util.IdentityHashMap.values() definition code for java.util.IdentityHashMap.values() ()
          Returns a collection view of the values contained in this map.
 
Methods inherited from class java.util.AbstractMap sample code for java.util.AbstractMap definition code for java.util.AbstractMap
toString sample code for java.util.AbstractMap.toString() definition code for java.util.AbstractMap.toString()
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

IdentityHashMap sample code for java.util.IdentityHashMap() definition code for java.util.IdentityHashMap()

public IdentityHashMap()
Constructs a new, empty identity hash map with a default expected maximum size (21).


IdentityHashMap sample code for java.util.IdentityHashMap(int) definition code for java.util.IdentityHashMap(int)

public IdentityHashMap(int expectedMaxSize)
Constructs a new, empty map with the specified expected maximum size. Putting more than the expected number of key-value mappings into the map may cause the internal data structure to grow, which may be somewhat time-consuming.

Parameters:
expectedMaxSize - the expected maximum size of the map.
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if expectedMaxSize is negative

IdentityHashMap sample code for java.util.IdentityHashMap(java.util.Map<? extends K, ? extends V>) definition code for java.util.IdentityHashMap(java.util.Map<? extends K, ? extends V>)

public IdentityHashMap(Map sample code for java.util.Map definition code for java.util.Map <? extends K,? extends V> m)
Constructs a new identity hash map containing the keys-value mappings in the specified map.

Parameters:
m - the map whose mappings are to be placed into this map.
Throws:
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if the specified map is null.
Method Detail

size sample code for java.util.IdentityHashMap.size() definition code for java.util.IdentityHashMap.size()

public int size()
Returns the number of key-value mappings in this identity hash map.

Specified by:
size sample code for java.util.Map.size() definition code for java.util.Map.size() in interface Map sample code for java.util.Map definition code for java.util.Map <K,V>
Overrides:
size sample code for java.util.AbstractMap.size() definition code for java.util.AbstractMap.size() in class AbstractMap sample code for java.util.AbstractMap definition code for java.util.AbstractMap <K,V>
Returns:
the number of key-value mappings in this map.

isEmpty sample code for java.util.IdentityHashMap.isEmpty() definition code for java.util.IdentityHashMap.isEmpty()

public boolean isEmpty()
Returns true if this identity hash map contains no key-value mappings.

Specified by:
isEmpty sample code for java.util.Map.isEmpty() definition code for java.util.Map.isEmpty() in interface Map sample code for java.util.Map definition code for java.util.Map <K,V>
Overrides:
isEmpty sample code for java.util.AbstractMap.isEmpty() definition code for java.util.AbstractMap.isEmpty() in class AbstractMap sample code for java.util.AbstractMap definition code for java.util.AbstractMap <K,V>
Returns:
true if this identity hash map contains no key-value mappings.

get sample code for java.util.IdentityHashMap.get(java.lang.Object) definition code for java.util.IdentityHashMap.get(java.lang.Object)

public V get(Object sample code for java.lang.Object definition code for java.lang.Object  key)
Returns the value to which the specified key is mapped in this identity hash map, or null if the map contains no mapping for this key. A return value of null does not necessarily indicate that the map contains no mapping for the key; it is also possible that the map explicitly maps the key to null. The containsKey method may be used to distinguish these two cases.

Specified by:
get sample code for java.util.Map.get(java.lang.Object) definition code for java.util.Map.get(java.lang.Object) in interface Map sample code for java.util.Map definition code for java.util.Map <K,V>
Overrides:
get sample code for java.util.AbstractMap.get(java.lang.Object) definition code for java.util.AbstractMap.get(java.lang.Object) in class AbstractMap sample code for java.util.AbstractMap definition code for java.util.AbstractMap <K,V>
Parameters:
key - the key whose associated value is to be returned.
Returns:
the value to which this map maps the specified key, or null if the map contains no mapping for this key.
See Also:
put(Object, Object) sample code for java.util.IdentityHashMap.put(K, V) definition code for java.util.IdentityHashMap.put(K, V)

containsKey sample code for java.util.IdentityHashMap.containsKey(java.lang.Object) definition code for java.util.IdentityHashMap.containsKey(java.lang.Object)

public boolean containsKey(Object sample code for java.lang.Object definition code for java.lang.Object  key)
Tests whether the specified object reference is a key in this identity hash map.

Specified by:
containsKey sample code for java.util.Map.containsKey(java.lang.Object) definition code for java.util.Map.containsKey(java.lang.Object) in interface Map sample code for java.util.Map definition code for java.util.Map <K,V>
Overrides:
containsKey sample code for java.util.AbstractMap.containsKey(java.lang.Object) definition code for java.util.AbstractMap.containsKey(java.lang.Object) in class AbstractMap sample code for java.util.AbstractMap definition code for java.util.AbstractMap <K,V>
Parameters:
key - possible key.
Returns:
true if the specified object reference is a key in this map.
See Also:
containsValue(Object) sample code for java.util.IdentityHashMap.containsValue(java.lang.Object) definition code for java.util.IdentityHashMap.containsValue(java.lang.Object)

containsValue sample code for java.util.IdentityHashMap.containsValue(java.lang.Object) definition code for java.util.IdentityHashMap.containsValue(java.lang.Object)

public boolean containsValue(Object sample code for java.lang.Object definition code for java.lang.Object  value)
Tests whether the specified object reference is a value in this identity hash map.

Specified by:
containsValue sample code for java.util.Map.containsValue(java.lang.Object) definition code for java.util.Map.containsValue(java.lang.Object) in interface Map sample code for java.util.Map definition code for java.util.Map <K,V>
Overrides:
containsValue sample code for java.util.AbstractMap.containsValue(java.lang.Object) definition code for java.util.AbstractMap.containsValue(java.lang.Object) in class AbstractMap sample code for java.util.AbstractMap definition code for java.util.AbstractMap <K,V>
Parameters:
value - value whose presence in this map is to be tested.
Returns:
true if this map maps one or more keys to the specified object reference.
See Also:
containsKey(Object) sample code for java.util.IdentityHashMap.containsKey(java.lang.Object) definition code for java.util.IdentityHashMap.containsKey(java.lang.Object)

put sample code for java.util.IdentityHashMap.put(K, V) definition code for java.util.IdentityHashMap.put(K, V)

public V put(K key,
             V value)
Associates the specified value with the specified key in this identity hash map. If the map previously contained a mapping for this key, the old value is replaced.

Specified by:
put sample code for java.util.Map.put(K, V) definition code for java.util.Map.put(K, V) in interface Map sample code for java.util.Map definition code for java.util.Map <K,V>
Overrides:
put sample code for java.util.AbstractMap.put(K, V) definition code for java.util.AbstractMap.put(K, V) in class AbstractMap sample code for java.util.AbstractMap definition code for java.util.AbstractMap <K,V>
Parameters:
key - the key with which the specified value is to be associated.
value - the value to be associated with the specified key.
Returns:
the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with the specified key.)
See Also:
Object.equals(Object) sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , get(Object) sample code for java.util.IdentityHashMap.get(java.lang.Object) definition code for java.util.IdentityHashMap.get(java.lang.Object) , containsKey(Object) sample code for java.util.IdentityHashMap.containsKey(java.lang.Object) definition code for java.util.IdentityHashMap.containsKey(java.lang.Object)

putAll sample code for java.util.IdentityHashMap.putAll(java.util.Map<? extends K, ? extends V>) definition code for java.util.IdentityHashMap.putAll(java.util.Map<? extends K, ? extends V>)

public void putAll(Map sample code for java.util.Map definition code for java.util.Map <? extends K,? extends V> t)
Copies all of the mappings from the specified map to this map These mappings will replace any mappings that this map had for any of the keys currently in the specified map.

Specified by:
putAll sample code for java.util.Map.putAll(java.util.Map) definition code for java.util.Map.putAll(java.util.Map) in interface Map sample code for java.util.Map definition code for java.util.Map <K,V>
Overrides:
putAll sample code for java.util.AbstractMap.putAll(java.util.Map) definition code for java.util.AbstractMap.putAll(java.util.Map) in class AbstractMap sample code for java.util.AbstractMap definition code for java.util.AbstractMap <K,V>
Parameters:
t - mappings to be stored in this map.
Throws:
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if the specified map is null.

remove sample code for java.util.IdentityHashMap.remove(java.lang.Object) definition code for java.util.IdentityHashMap.remove(java.lang.Object)

public V remove(Object sample code for java.lang.Object definition code for java.lang.Object  key)
Removes the mapping for this key from this map if present.

Specified by:
remove sample code for java.util.Map.remove(java.lang.Object) definition code for java.util.Map.remove(java.lang.Object) in interface Map sample code for java.util.Map definition code for java.util.Map <K,V>
Overrides:
remove sample code for java.util.AbstractMap.remove(java.lang.Object) definition code for java.util.AbstractMap.remove(java.lang.Object) in class AbstractMap sample code for java.util.AbstractMap definition code for java.util.AbstractMap <K,V>
Parameters:
key - key whose mapping is to be removed from the map.
Returns:
previous value associated with specified key, or null if there was no entry for key. (A null return can also indicate that the map previously associated null with the specified key.)

clear sample code for java.util.IdentityHashMap.clear() definition code for java.util.IdentityHashMap.clear()

public void clear()
Removes all mappings from this map.

Specified by:
clear sample code for java.util.Map.clear() definition code for java.util.Map.clear() in interface Map sample code for java.util.Map definition code for java.util.Map <K,V>
Overrides:
clear sample code for java.util.AbstractMap.clear() definition code for java.util.AbstractMap.clear() in class AbstractMap sample code for java.util.AbstractMap definition code for java.util.AbstractMap <K,V>

equals sample code for java.util.IdentityHashMap.equals(java.lang.Object) definition code for java.util.IdentityHashMap.equals(java.lang.Object)

public boolean equals(Object sample code for java.lang.Object definition code for java.lang.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 map this.entrySet().equals(m.entrySet()).

Owing to the reference-equality-based semantics of this map it is possible that the symmetry and transitivity requirements of the Object.equals contract may be violated if this map is compared to a normal map. However, the Object.equals contract is guaranteed to hold among IdentityHashMap instances.

Specified by:
equals sample code for java.util.Map.equals(java.lang.Object) definition code for java.util.Map.equals(java.lang.Object) in interface Map sample code for java.util.Map definition code for java.util.Map <K,V>
Overrides:
equals sample code for java.util.AbstractMap.equals(java.lang.Object) definition code for java.util.AbstractMap.equals(java.lang.Object) in class AbstractMap sample code for java.util.AbstractMap definition code for java.util.AbstractMap <K,V>
Parameters:
o - object to be compared for equality with this map.
Returns:
true if the specified object is equal to this map.
See Also:
Object.equals(Object) sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object)

hashCode sample code for java.util.IdentityHashMap.hashCode() definition code for java.util.IdentityHashMap.hashCode()

public int hashCode()
Returns the hash code value for this map. The hash code of a map is defined to be the sum of the hashcode of each entry in the map's entrySet view. This ensures that t1.equals(t2) implies that t1.hashCode()==t2.hashCode() for any two IdentityHashMap instances t1 and t2, as required by the general contract of Object.hashCode() sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() .

Owing to the reference-equality-based semantics of the Map.Entry instances in the set returned by this map's entrySet method, it is possible that the contractual requirement of Object.hashCode mentioned in the previous paragraph will be violated if one of the two objects being compared is an IdentityHashMap instance and the other is a normal map.

Specified by:
hashCode sample code for java.util.Map.hashCode() definition code for java.util.Map.hashCode() in interface Map sample code for java.util.Map definition code for java.util.Map <K,V>
Overrides:
hashCode sample code for java.util.AbstractMap.hashCode() definition code for java.util.AbstractMap.hashCode() in class AbstractMap sample code for java.util.AbstractMap definition code for java.util.AbstractMap <K,V>
Returns:
the hash code value for this map.
See Also:
Object.hashCode() sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , Object.equals(Object) sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , equals(Object) sample code for java.util.IdentityHashMap.equals(java.lang.Object) definition code for java.util.IdentityHashMap.equals(java.lang.Object)

clone sample code for java.util.IdentityHashMap.clone() definition code for java.util.IdentityHashMap.clone()

public Object sample code for java.lang.Object definition code for java.lang.Object  clone()
Returns a shallow copy of this identity hash map: the keys and values themselves are not cloned.

Overrides:
clone sample code for java.util.AbstractMap.clone() definition code for java.util.AbstractMap.clone() in class AbstractMap sample code for java.util.AbstractMap definition code for java.util.AbstractMap <K,V>
Returns:
a shallow copy of this map.
See Also:
Cloneable sample code for java.lang.Cloneable definition code for java.lang.Cloneable

keySet sample code for java.util.IdentityHashMap.keySet() definition code for java.util.IdentityHashMap.keySet()

public Set sample code for java.util.Set definition code for java.util.Set <K> keySet()
Returns an identity-based set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll retainAll, and clear methods. It does not support the add or addAll methods.

While the object returned by this method implements the Set interface, it does not obey Set's general contract. Like its backing map, the set returned by this method defines element equality as reference-equality rather than object-equality. This affects the behavior of its contains, remove, containsAll, equals, and hashCode methods.

The equals method of the returned set returns true only if the specified object is a set containing exactly the same object references as the returned set. The symmetry and transitivity requirements of the Object.equals contract may be violated if the set returned by this method is compared to a normal set. However, the Object.equals contract is guaranteed to hold among sets returned by this method.

The hashCode method of the returned set returns the sum of the identity hashcodes of the elements in the set, rather than the sum of their hashcodes. This is mandated by the change in the semantics of the equals method, in order to enforce the general contract of the Object.hashCode method among sets returned by this method.

Specified by:
keySet sample code for java.util.Map.keySet() definition code for java.util.Map.keySet() in interface Map sample code for java.util.Map definition code for java.util.Map <K,V>
Overrides:
keySet sample code for java.util.AbstractMap.keySet() definition code for java.util.AbstractMap.keySet() in class AbstractMap sample code for java.util.AbstractMap definition code for java.util.AbstractMap <K,V>
Returns:
an identity-based set view of the keys contained in this map.
See Also:
Object.equals(Object) sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , System.identityHashCode(Object) sample code for java.lang.System.identityHashCode(java.lang.Object) definition code for java.lang.System.identityHashCode(java.lang.Object)

values sample code for java.util.IdentityHashMap.values() definition code for java.util.IdentityHashMap.values()

public Collection sample code for java.util.Collection definition code for java.util.Collection <V> values()

Returns a collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress, the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear methods. It does not support the add or addAll methods.

While the object returned by this method implements the Collection interface, it does not obey Collection's general contract. Like its backing map, the collection returned by this method defines element equality as reference-equality rather than object-equality. This affects the behavior of its contains, remove and containsAll methods.

Specified by:
values sample code for java.util.Map.values() definition code for java.util.Map.values() in interface Map sample code for java.util.Map definition code for java.util.Map <K,V>
Overrides:
values sample code for java.util.AbstractMap.values()