Share on Google+Share on Google+

SCJP Module-9 Question-8

Advertisement
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

Answer

(2)

Explanation

headSet(10)  Returns the elements which are strictly less than 10.

Advertisements

Posted on: July 16, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.