VOOZH about

URL: https://www.geeksforgeeks.org/java/collections-synchronizedlist-method-in-java-with-examples/

⇱ Collections synchronizedList() method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Collections synchronizedList() method in Java with Examples

Last Updated : 8 Oct, 2018
The synchronizedList() method of java.util.Collections class is used to return a synchronized (thread-safe) list backed by the specified list. In order to guarantee serial access, it is critical that all access to the backing list is accomplished through the returned list. Syntax:
public static <T> List<T>
 synchronizedList(List<T> list)
Parameters: This method takes the list as a parameter to be "wrapped" in a synchronized list. Return Value: This method returns a synchronized view of the specified list. Below are the examples to illustrate the synchronizedList() method Example 1:
Output:
List : [A, B, C, D, E]
Synchronized list is : [A, B, C, D, E]
Example 2:
Output:
List : [20, 30, 40, 50, 60]
Synchronized list is : [20, 30, 40, 50, 60]
Comment