Listlist = new ArrayList<>(); List synchronizedList = Collections.synchronizedCollection(list);
MapIn this example, we create a HashMap of Integer and String objects and then create a synchronizedMap using the synchronizedCollection method. The synchronizedMap is now thread-safe and can be safely accessed and modified by multiple threads. The synchronizedCollection method is part of the java.util.Collections package library.map = new HashMap<>(); Map synchronizedMap = Collections.synchronizedCollection(map);