Java Utililty Methods List Flatten

List of utility methods to do List Flatten

Description

The list of methods to do List Flatten are organized into topic(s).

Method

Listflatten(List> list)
flatten
List<T> flat = new ArrayList<>();
for (Collection<T> collection : list) {
    flat.addAll(collection);
return flat;
ArrayListflatten(List input)
flatten
ArrayList<Object> result = new ArrayList<Object>();
for (Object o : input) {
    if (o instanceof List<?>) {
        result.addAll(flatten((List<?>) o));
    } else {
        result.add(o);
return result;
voidflatten(List list, List flat)
Helper method to flatten a potential list of lists into a list of objects.
for (Object item : list) {
    if (item instanceof List<?>) {
        flatten((List<?>) item, flat);
    } else {
        flat.add(item);
ArrayListflatten(List> nested)
flatten
ArrayList<T> flat = new ArrayList<>();
for (List<T> subList : nested) {
    flat.addAll(subList);
return flat;
Listflatten(List>... deeps)
flatten
List<T> result = new LinkedList<>();
for (List<List<T>> deep : deeps) {
    for (List<T> list : deep) {
        result.addAll(list);
return result;
Stringflatten(List l)
flatten
StringBuilder sb = new StringBuilder();
for (String s : l) {
    if (sb.length() > 0)
        sb.append(",");
    sb.append(s);
return sb.toString();
ListflattenList(List> listOfLists)
flatten List
List<T> flatList = new ArrayList<T>();
listOfLists.forEach(flatList::addAll);
return flatList;