1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
/* Get Synchronized List from Java ArrayList example This java example shows how to get a synchronized list from Java ArrayList using synchronizedList method of Collections class. */ import java.util.ArrayList; import java.util.Collections; import java.util.List; public class GetSynchronizedListFromArrayListExample { public static void main(String[] args) { //create an ArrayList object ArrayList arrayList = new ArrayList(); /* Java ArrayList is NOT synchronized. To get synchronized list from ArrayList use static void synchronizedList(List list) method of Collections class. */ List list = Collections.synchronizedList(arrayList); /* Use this list object to prevent any unsynchronized access to original ArrayList object. */ } } |
Add Comment