Java Collections.checkedSet(Set <E> s, Class <E> type)
Syntax
Collections.checkedSet(Set <E> s, Class <E> type) has the following syntax.
public static <E> Set <E> checkedSet(Set <E> s, Class <E> type)
Example
In the following code shows how to use Collections.checkedSet(Set <E> s, Class <E> type) method.
/* w ww . j a v a 2 s . c o m*/
import java.util.Collections;
import java.util.Set;
import java.util.TreeSet;
public class Main {
public static void main(String args[]) {
Set<String> hset = new TreeSet<String> ();
// populate the set
hset.add("from");
hset.add("java2s.com");
hset.add("tutorial");
// get typesafe view of the set
Set<String> tsset = Collections.checkedSet(hset,String.class);
System.out.println(tsset);
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »