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