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

后端 未结 9 614
春和景丽
春和景丽 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:27

    You can use the flatCollect() pattern from Eclipse Collections.

    MutableList> list = Lists.mutable.empty();
    MutableList flat = list.flatCollect(each -> each);
    
    
    

    If you can't change list from List:

    List> list = new ArrayList<>();
    List flat = ListAdapter.adapt(list).flatCollect(each -> each);
    
    
    

    Note: I am a contributor to Eclipse Collections.

    提交回复
    热议问题