Quantcast
Channel: Java Hashmap: How to get key from value? - Stack Overflow
Viewing all articles
Browse latest Browse all 41

Answer by smftr for Java Hashmap: How to get key from value?

$
0
0

let see my example

Map<String, String> mapPeopleAndCountry = new HashMap<>();mapPeopleAndCountry.put("Matis", "Lithuania");mapPeopleAndCountry.put("Carlos", "Honduras");mapPeopleAndCountry.put("Teboho", "Lesotho");mapPeopleAndCountry.put("Marielos", "Honduras");List<String> peopleInHonduras = mapPeopleAndCountry.keySet()    .stream()    .filter(r -> mapPeopleAndCountry.get(r)                .equals("Honduras"))    .stream(Collectors.toList());// will return ["Carlos", "Marielos"]

Note: untested, may contains typo


Viewing all articles
Browse latest Browse all 41

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>