My question is very simple, but I could not find a solution myself.
I use to write algorithms in C ++. There, I very often use the std::map
structure, as well as all the helper methods that it provides.
This method returns the iterator to the first element of the map with the key> = to the key specified as a parameter. Example:
map<int, string> m; // m = { 4 => "foo", 6 => "bar", 10 => "abracadabra" } m.lower_bound(2); // returns iterator pointing to <4, "foo"> m.lower_bound(4); // returns iterator pointing to <4, "foo"> m.lower_bound(5); // returns iterator pointing to <6, "bar">
Most interestingly, the C ++ map is based on red-black trees, so the request is logarithmic ( O(log n)
).
Now I need to implement a specific algorithm in Java. I need the same functionality as described by me. I know that I can use TreeMap
, which is implemented in an ordered tree. However, it seems I did not find the equivalent of the lower_bound
method. Are there any?
Many thanks for your help.
source share