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

 
 

Share on Google+Share on Google+
SCJP Module-9 Question-7
Posted on: July 16, 2010 at 12:00 AM
Advertisement
The given sample program will test your understanding of NavigableSet, newTreeSet of Collection framework of Java

Given below the sample code :

import java.util.ArrayList;
import java.util.List;
import java.util.NavigableSet;
import java.util.TreeSet;
public class Check {
public static void main(String... args) {
List<Integer> l = new ArrayList<Integer>();
lst.add(12);
lst.add(6);
lst.add(2);
lst.add(3);
lst.add(30);
lst.add(21);
NavigableSet<Integer> nset = newTreeSet(l);
System.out.println(nset.lower(4)+" "+nset.higher(4)+ " "+ nset.lower(2));
}
}

What will be the output of the above code?

1.Compile error

2. 3  6  null

3. null 6 12

4. null 6 null

Answer

(2)

Explanation

lower() It returns the largest element in this set strictly less than the provided element,
or null if there is no such element.
higher() It returns the lowest element in this set strictly greater than the provided element,
or null if there is no such element.

Advertisement

Related Tags for SCJP Module-9 Question-7:


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