Thread-Safe Collections : Thread Safe Collections « Thread « Java Tutorial






public static Collection synchronizedCollection(Collection c)
public static List synchronizedList(List l)
public static Map synchronizedMap(Map m)
public static Set synchronizedSet(Set s)
public static SortedMap synchronizedSortedMap(SortedMap m)
public static SortedSet synchronizedSortedSet(SortedSet s)
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public class MainClass {
  public static void main(String[] a) {
    Set s = new HashSet();
    s.add("A");
    s.add("B");
    s.add("C");
    s.add("D");
    s.add("E");
    s.add("F");
    s.add("H");
    Collections.synchronizedSet(s);
  }
}








10.8.Thread Safe Collections
10.8.1.Thread-Safe Collections