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

 
 

SCJP Module-9 Question-2
Posted on: July 16, 2010 at 12:00 AM
The sample program given below will test your knowledge of List, NavigableSet, TreeSet of collection framework in Java.

Given below the sample code :

import java.util.ArrayList;
import java.util.List;
import java.util.NavigableSet;
import java.util.TreeSet;
public class CheckTail{
public static void main(String... args) {
List<Integer> MyList = new ArrayList<Integer>();
MyList.add(21);
MyList.add(3);
MyList.add(3);
MyList.add(3);
MyList.add(30);
MyList.add(2);
NavigableSet<Integer> ngs = new TreeSet<Integer>(MyList);
System.out.println(ngs.tailSet(3));
}
}

What will be the output of the above code ?

1. Compilation error

2. [21, 3, 30, 2]

3. [3, 30, 2]

4. [ 3, 21, 30]

Answer

(4)

Explanation

The ' tailSet(3) ' returns elements which are greater than or equal to 3.

 

 

Related Tags for SCJP Module-9 Question-2:


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.