Without testing, something like this should work:
return map.entrySet()
.stream()
.filter(e-> e.getValue().searchTerm.equalsIgnoreCase(searchTerm))
.findFirst()
.map(Map.Entry::getKey)
.orElse(-1);
This is a combination of finding a match in the stream entrySetand returning either the key if a match is found, or -1.
source
share