Collections.synchronizedList(List <T> list) has the following syntax.
public static <T> List <T> synchronizedList(List <T> list)
In the following code shows how to use Collections.synchronizedList(List <T> list) method.
import java.util.ArrayList; import java.util.Collections; import java.util.List; //from ww w. ja v a 2 s. c om public class Main { public static void main(String[] args) { List<String> list = new ArrayList<String> (); // populate the list list.add("1"); list.add("2"); list.add("3"); list.add("4"); list.add("from java2s.com"); // create a synchronized list List<String> synlist = Collections.synchronizedList(list); System.out.println("Sunchronized list is :"+synlist); } }
The code above generates the following result.