// collectiontopics/Synchronization.java // (c)2021 MindView LLC: see Copyright.txt // We make no guarantees that this code is fit for any purpose. // Visit http://OnJava8.com for more book information. // Using the Collections.synchronized methods import java.util.*; public class Synchronization { public static void main(String[] args) { Collection c = Collections.synchronizedCollection( new ArrayList<>()); List list = Collections .synchronizedList(new ArrayList<>()); Set s = Collections .synchronizedSet(new HashSet<>()); Set ss = Collections .synchronizedSortedSet(new TreeSet<>()); Map m = Collections .synchronizedMap(new HashMap<>()); Map sm = Collections .synchronizedSortedMap(new TreeMap<>()); } }