Answers for "how to search through map to see which key has the value java"

0

access each key and value in a hashmap java

// access each key and corresponding value in a hashmap
HashMap<Integer, Integer> map = new HashMap<>();

for(Map.Entry<Integer, Integer> entry : map.entrySet()){
  entry.getKey();
  entry.getValue();
}
Posted by: Guest on December-03-2020
2

java map get the key from value

public static <T, E> Set<T> getKeyByValue(Map<T, E> map, E value) {
    return map.entrySet()
              .stream()
              .filter(entry -> Objects.equals(entry.getValue(), value))
              .map(Map.Entry::getKey)
              .collect(Collectors.toSet());
}
Posted by: Guest on March-06-2020

Code answers related to "how to search through map to see which key has the value java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language