Package java.util
Class Collections

Public Method synchronizedCollection

static Collection synchronizedCollection(Collection c)

_INSERT_METHOD_SIGNATURE_HERE_

Description:

Returns a synchronized (thread-safe) collection backed by the specified collection. Changes in the returned sorted set are reflected in this set, and vice-versa. In order to guarantee serial access, it is critical that all access to the backing collection is accomplished through the returned collection.

The user has to manually synchronize on the returned collection when iterating over it:

synchronized(MyCollection) { // iterate in a synchronized block

Iterator i = MyCollection.iterator();

while (i.hasNext())

myFun(i.next());

}

The returned collection does not pass the hashCode and equals operations through to the backing collection, but relies on Object's equals and hashCode methods. This is necessary to preserve the contracts of these operations in the case that the backing collection is a set or a list. The returned collection will be serializable if the specified collection is serializable.