java.util.Collections
class provides static methods to return synchroni collection backed by the specified collection. Following are the methods provided by Collections class:
- Collections.synchronizedCollection(Collection<T> c)
- Collections.synchronizedList(List<T> list)
- Collections.synchronizedMap(Map<K,V> m)
- Collections.synchronizedSet(Set<T> s)
- Collections.synchronizedSortedMap(SortedMap<K,V> m)
- Collections.synchronizedSortedSet(SortedSet<T> s)
For example, to create synchronized list:
List<String> list = new ArrayList(); List<String> synchronizedList = Collections.synchronizedList(list);