3 ways to flatten a list of lists. Is there a reason to prefer one of them?

前端 未结 3 1141
孤独总比滥情好
孤独总比滥情好 2021-02-07 04:18

Assume we have a list as follows. CoreResult has a field of type List.

final List list = new LinkedList         


        
3条回答
  •  别跟我提以往
    2021-02-07 04:56

    I would go for option 2 or 3. If you want to flatten a List>, you would do this:

    List list = doubleList.stream()
                                  .flatMap(List::stream)
                                  .collect(Collectors.toList());
    

提交回复
热议问题