Synchronized List In Java
Chapter:
Collections
Last Updated:
21-06-2016 20:07:12 UTC
Program:
/* ............... START ............... */
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class JavaSynchronizedListExample {
public static void main(String a[]){
List<String> arrayList = new ArrayList<String>();
List<String> synchronizedList = Collections.synchronizedList(arrayList);
System.out.println("Synchronized list has been created.");
}
}
/* ............... END ............... */
Output
Synchronized list has been created.
Notes:
-
The ArrayList is not synchornized (not thread-safe).
- Collections.synchronizedList() method helps to get thread safe list.
Tags
Synchronized List, Java, Collection