Share on Google+Share on Google+

SCJP Module-9 Question-2

Advertisement
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.

 

 

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.