Java tutorial
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); } }