Home Tutorial Java Scjp Part9 SCJP Module-9 Question-8

 
 

SCJP Module-9 Question-8
Posted on: July 16, 2010 at 12:00 AM
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.

Related Tags for SCJP Module-9 Question-8:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.