Java Collection Tutorial - Java Collections .checkedCollection ( Collection <E> c, Class <E> type)








Syntax

Collections.checkedCollection(Collection <E> c, Class <E> type) has the following syntax.

public static <E> Collection <E> checkedCollection(Collection <E> c,     Class <E> type)

Example

In the following code shows how to use Collections.checkedCollection(Collection <E> c, Class <E> type) method.

/*w ww  . ja v  a  2  s  .co  m*/
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class Main {
   public static void main(String args[]) {
      List<String>  arlst = new ArrayList<String> ();
      
      // populate the list
      arlst.add("CSS");
      arlst.add("PHP");
      arlst.add("HTML");
      arlst.add("java2s.com");
      
      // create typesafe view of the collection
      Collection<String>  tslst = Collections.checkedCollection(arlst,String.class);     
      
      System.out.println(tslst);
   }    
}

The code above generates the following result.