Java Hashmap: How to get key from value?

前端 未结 30 2245
忘掉有多难
忘掉有多难 2020-11-22 02:14

If I have the value \"foo\", and a HashMap ftw for which ftw.containsValue(\"foo\") returns true, how can I

30条回答
  •  轮回少年
    2020-11-22 03:11

    In java8

    map.entrySet().stream().filter(entry -> entry.getValue().equals(value))
        .forEach(entry -> System.out.println(entry.getKey()));
    

提交回复
热议问题