Java Collections .synchronizedCollection ( Collection <T> c)

Syntax

Collections.synchronizedCollection(Collection <T> c) has the following syntax.

public static <T> Collection <T> synchronizedCollection(Collection <T> c)

Example

In the following code shows how to use Collections.synchronizedCollection(Collection <T> c) method.


import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
//from w  w  w  . j a va2 s  .c o  m
public class Main {
   public static void main(String[] args) {
      // create vector object 
      List<String>  vector = new ArrayList<String> ();
      
      // populate the vector
      vector.add("1");
      vector.add("2");
      vector.add("3");
      vector.add("4");
      vector.add("from java2s.com");
      
      // create a synchronized view
      Collection<String>  c = Collections.synchronizedCollection(vector);
     
      System.out.println("Sunchronized view is :"+c);
   }
}

The code above generates the following result.