Online Java Compiler By
JavaTpoint.com
import java.util.*; public class CollectionsCheckedNavigableSetExample3 { public static void main(String[] args) { NavigableSet
set = new TreeSet<>(); //Insert values in the Map set.add("A"); set.add("B"); set.add("A"); set.add("B"); System.out.println("Type safe view of the Navigable Set1 is: "+Collections.checkedNavigableSet(set,String.class)); NavigableSet
sset = new TreeSet<>(); sset.add(11); sset.add(12); sset.add(11); sset.add(12); //Create type safe view of the Map System.out.println("Type safe view of the Navigable Set2 is: "+Collections.checkedNavigableSet(sset,Integer.class)); Set sset2 = sset; sset2.add("two"); System.out.println("TypeSafe View: "+sset2); } }
Output