Java Synchronized Collection
Synchronized Collections is nothing but a thread safe collections, to convert normal collection classes to a Synchronized Collections we have a method named as synchronizedCollection(Collection
When we invoke the synchronizedCollection(Collection
synchronizedCollection(Collection
public staticCollection synchronizedCollection(Collection c) { return new SynchronizedCollection<>(c); }
synchronized Collection example
import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; public class SynchronizedCollection { public static void main(String[] args) { List stringList=new ArrayList(); stringList.add("Synchronized"); stringList.add("Collections"); stringList.add("In"); stringList.add("Java"); Collection synchronizedCollection=Collections.synchronizedCollection(stringList); System.out.println(synchronizedCollection); } }Output
[Synchronized, Collections, In, Java]