Hashmap with Streams in Java 8 Streams to collect value of Map

后端 未结 6 1838
悲&欢浪女
悲&欢浪女 2021-01-30 19:59

Let consider a hashmap

Map id1 = new HashMap();

I inserted some values into both hashmap.

For

6条回答
  •  孤独总比滥情好
    2021-01-30 20:29

    For your Q2, there are already answers to your question. For your Q1, and more generally when you know that the key's filtering should give a unique value, there's no need to use Streams at all.

    Just use get or getOrDefault, i.e:

    List list1 = id1.getOrDefault(1, Collections.emptyList());
    

提交回复
热议问题