How can I turn a List of Lists into a List in Java 8?

后端 未结 9 783
春和景丽
春和景丽 2020-11-22 04:49

If I have a List>, how can I turn that into a List that contains all the objects in the same iteration order
9条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 05:12

    flatmap is better but there are other ways to achieve the same

    List> listOfList = ... // fill
    
    List collect = 
          listOfList.stream()
                    .collect(ArrayList::new, List::addAll, List::addAll);
    
        

    提交回复
    热议问题