Java Collections .checkedSortedMap ( SortedMap <K,V> m, Class <K> keyType, Class <V> valueType)
Syntax
Collections.checkedSortedMap(SortedMap <K,V> m, Class <K> keyType, Class <V> valueType) has the following syntax.
public static
<K,V> SortedMap <K,V> checkedSortedMap(SortedMap <K,V> m,
Class <K> keyType,
Class <V> valueType)
Example
In the following code shows how to use Collections.checkedSortedMap(SortedMap <K,V> m, Class <K> keyType, Class <V> valueType) method.
// w w w.j av a 2 s . c o m
import java.util.Collections;
import java.util.SortedMap;
import java.util.TreeMap;
public class Main {
public static void main(String args[]) {
SortedMap<String,String> smap = new TreeMap<String,String>();
smap.put("1", "tutorial");
smap.put("2", "from");
smap.put("3", "java2s.com");
// get typesafe view of the sorted map
SortedMap<String,String> tsmap
= Collections.checkedSortedMap(smap,String.class,String.class);
System.out.println(tsmap);
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »