How to retainAll of List of Lists using stream reduce

后端 未结 2 2038
[愿得一人]
[愿得一人] 2021-01-05 09:34

I faced following problem. I have a list of lists which i simply want to retainAll. I\'m trying to do with streams

private List> ids =         


        
2条回答
  •  醉梦人生
    2021-01-05 10:12

    addAll returns a boolean, not the union of the two lists. You want

    List reduce = ids.stream().reduce(ids.get(0), (a, b) -> {
        a.addAll(b);
        return a;
    });
    

提交回复
热议问题