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

 
 

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

 

 

Advertisement

Related Tags for SCJP Module-9 Question-2:


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.

Posted on: July 16, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com