Online Java Compiler By
JavaTpoint.com
import java.util.*; public class CollectionsCheckedSortedMapExample3 { public static void main(String[] args) { //create map SortedMap
map = new TreeMap<>(); map = Collections.checkedSortedMap(map,Integer.class, String.class); map.put(1100, "JavaTpoint"); map.put(500, "Hindi100"); map.put(1800, "SSSIT"); map.put(900, "ABCD"); //Get type safe view of sorted map System.out.println("Map content: "+map); SortedMap map2 = map; map2.put(5,500); map2.put(6,200); //throws ClassCastException } }
Output