I have written an article on how to implement lower_bound() function of C++ in Java by creating our own method and also using java inbuilt functions. Feel free to comment if you have any query.
Link: https://medium.com/@ssrivastava990/alternative-implementation-of-lower-bound-in-java-23ec40a825ec
This all seems rather unnecessary to me. You already have treeset.higher(), .lower(), .floor(), and .ceil(). In my experience (as a java main), no one seriously wants to convert from C++ to Java. Even if they did, the names of the methods in Java are super self-explanatory. i. e. "I want the first thing higher than x" "Okay, then use .higher(x)".
He talks about arrays, not sets. Arrays.binarySearch() is stupid returning random occurence, and you have to use pairs (value, index) to find first/last occurence or write it manually
If I were a Java user, I would use generic types so that any that the methods work for any class that implements the Comparable interface. Also I would make it return the end of the range if the search fails to be consistent with C++. Also in my experience from the Kotlin round, ArrayList is much slower than int[], so it would be worth it to implement the methods separately for each primitive type or find some way to convert a primitive array to an ArrayList in O(1).
Generic implementation of lower_bound and upper_bound:- https://paste.ubuntu.com/p/rGgJ5ypj8t/