C++ functions upper_bound() and lower_bound() implementation in java

For a long time now I’ve been trying to find a java replacement for the upperbound and lowerbound functions in C++ but the functions I come across are always half correct giving correct answer for some and wrong answer for other cases. Can someone please help me with a 100% working java implementation of the same.

Why don’t you make own upper and lower bound functions using binary search in this way you will always get correct answers . You can see here for more details .