Here you can find the source of flatten(List> nested)
public static <T> ArrayList<T> flatten(List<List<T>> nested)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; public class Main { public static <T> ArrayList<T> flatten(List<List<T>> nested) { ArrayList<T> flat = new ArrayList<>(); for (List<T> subList : nested) { flat.addAll(subList);/*w ww .jav a2 s . c om*/ } return flat; } }