Here you can find the source of flatten(List> input)
public static ArrayList<?> flatten(List<?> input)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; public class Main { public static ArrayList<?> flatten(List<?> input) { ArrayList<Object> result = new ArrayList<Object>(); for (Object o : input) { if (o instanceof List<?>) { result.addAll(flatten((List<?>) o)); } else { result.add(o);/*from w w w. j a va2 s . c o m*/ } } return result; } }