The given sample program will test your understanding of NavigableSet, newTreeSet of Collection framework of Java
The given sample program will test your understanding of NavigableSet, newTreeSet of Collection framework of JavaGiven 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
(2)
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.