Java 8 Stream Collecting Set

后端 未结 1 1653
谎友^
谎友^ 2020-12-13 12:20

To better understand the new stream API I\'m trying to convert some old code, but I\'m stuck on this one.

 public Collection asDestSet(         


        
相关标签:
1条回答
  • 2020-12-13 13:01

    Use flatMap:

    return map.values().stream().flatMap(Set::stream).collect(Collectors.toSet());
    

    The flatMap flattens all of your sets into single stream.

    0 讨论(0)
提交回复
热议问题