How to get the the greatest element in TreeSet which less than the given element N in Java

1 Answer

0 votes
import java.util.*; 

public class MyClass {
    public static void main(String args[]) {
        TreeSet<Integer> ts = new TreeSet<Integer>(); 
  
        ts.add(17); 
        ts.add(83); 
        ts.add(91); 
        ts.add(22); 
        ts.add(12); 
  
        System.out.println(ts.lower(21)); 
    }
}


/*
run:

17

*/

 



answered Apr 6, 2019 by avibootz
...