Since Java Map is not bidirectional, Value can be retrieved from Key, but Key cannot be retrieved from Value. There seems to be a list type library for that, but is there a good way to do it ...
Stream.of(fooMap)
.takeUntil(fooItem -> fooItem.getValue() == targetValue)
.findLast().get().getKey();
I'm writing this using the Lightweight-Stream-API, but I'm not sure if it's there. If possible, I'd like to search by O (1) ... I wonder if there is no choice but to make a map in the opposite direction?
Recommended Posts