Java Collections.checkedList(List <E> list, Class <E> type)
Syntax
Collections.checkedList(List <E> list, Class <E> type) has the following syntax.
public static <E> List <E> checkedList(List <E> list, Class <E> type)
Example
In the following code shows how to use Collections.checkedList(List <E> list, Class <E> type) method.
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
// w w w .j a v a 2 s . c o m
public class Main {
public static void main(String args[]) {
List<String> arlst=new ArrayList<String> ();
arlst.add("A");
arlst.add("B");
arlst.add("C");
arlst.add("from java2s.com");
// create typesafe view of the list
List<String> tslst = Collections.checkedList(arlst,String.class);
System.out.println(tslst);
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »