Higher and lower set
import java.util.TreeSet;
public class Main {
public static void main(String args[]) {
TreeSet<Integer> ts = new TreeSet<Integer>();
ts.add(8);
ts.add(19);
ts.add(-2);
ts.add(3);
System.out.println(ts);
System.out.println("First element in ts: " + ts.first());
System.out.println("Last element in ts: " + ts.last());
System.out.println("First element > 15: " + ts.higher(15));
System.out.println("First element < 15: " + ts.lower(15));
}
}
Output:
[-2, 3, 8, 19]
First element in ts: -2
Last element in ts: 19
First element > 15: 19
First element < 15: 8