The Sample example given below will test your knowledge of NavigableSet, TreeSet, List and ArrayList of Collection framework in Java.
The Sample example given below will test your knowledge of NavigableSet, TreeSet, List and ArrayList of Collection framework in Java.Given below the sample code :
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NavigableSet;
import java.util.TreeSet;
public class Check {
public static void main(String... args) {
List<Integer> mylist = new ArrayList<Integer>();
lst.add(21);
lst.add(3);
lst.add(6);
lst.add(9);
lst.add(30);
lst.add(12);
NavigableSet<Integer> nset = new TreeSet(mylist);
System.out.println(nset.headSet(10));
}
}
What will be the output of the above code ?
1. Compile error
2. 3 6 9
3. 12 21 30
4. 9
(2)
headSet(10) Returns the elements which are strictly less than 10.