Java Collection Flatten flatten(Collection list, Class type)

Here you can find the source of flatten(Collection list, Class type)

Description

flatten

License

Apache License

Declaration

public static <T> List<T> flatten(Collection<?> list, Class<T> type) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;
import java.util.Collection;

import java.util.List;

public class Main {
    public static <T> List<T> flatten(Collection<?> list, Class<T> type) {
        List<Object> retVal = new ArrayList<Object>();
        flatten(list, retVal);// w  w  w .  j a  v a  2  s .c o  m
        return (List<T>) retVal;
    }

    private static void flatten(Collection<?> fromTreeList, Collection<Object> toFlatList) {
        for (Object item : fromTreeList) {
            if (item instanceof Collection<?>) {
                flatten((Collection<?>) item, toFlatList);
            } else {
                toFlatList.add(item);
            }
        }
    }
}

Related

  1. flatten( Collection colOfCols)
  2. flatten(Class cls, Collection> collections)
  3. flatten(Collection> collections)
  4. flatten(Collection> cols)
  5. flatten(Collection l)
  6. flatten(Collection> nestedList)
  7. flatten(Collection> collOfLists)
  8. flatten(Collection collection, char separator)
  9. flatten(Collection original)