Share on Google+Share on Google+

SCJP Module-9 Question-29

Advertisement
The Sample program given below will test your understanding about the NavigableSet set in the Collection framework of Java.

Given below the sample code :

1  import java.util.ArrayList;
2  import java.util.List;
3  import java.util.NavigableSet;
4  import java.util.TreeSet;
5  public class Check {
6  public static void main(String... args) {
7  List<Integer> l = new ArrayList<Integer>();
8  lst.add(12);
9  lst.add(6);
10 lst.add(2);
11 lst.add(3);
12 lst.add(30);
13 lst.add(21);
14 NavigableSet<Integer> nset = newTreeSet(l);
15  // Place code here
16  }

What code line should be at line 15 to the print largest element  less than 12 in the given array list ?

1. System.out.println( nset.higher(12));

2. System.out.println( nset.lower(12));

3.System.out.println(nset.headSet(12));

4.No need to add any line.

Answer

(2)

Advertisements

Posted on: July 19, 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.