Java Utililty Methods Collection Flatten

List of utility methods to do Collection Flatten

Description

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

Method

Listflatten(Collection colOfCols)
flatten
int size = 0;
for (C col : colOfCols) {
    size += col.size();
ArrayList<T> list = new ArrayList<T>(size);
for (C col : colOfCols) {
    list.addAll(col);
return list;
Collectionflatten(Class cls, Collection> collections)
flatten
try {
    Collection<T> flatCollection = cls.newInstance();
    for (Collection<T> collection : collections) {
        flatCollection.addAll(collection);
    return flatCollection;
} catch (RuntimeException re) {
    throw re;
...
Listflatten(Collection> collections)
flatten
List<E> result = new ArrayList<E>();
for (Collection<E> list : collections) {
    result.addAll(list);
return result;
Collectionflatten(Collection> cols)
flatten
if (cols.size() == 0) {
    return Collections.emptyList();
} else if (cols.size() == 1) {
    return cols.iterator().next();
} else {
    Collection<V> result = new ArrayList<V>();
    for (Collection<V> c : cols) {
        for (V v : c) {
...
Listflatten(Collection l)
flatten
boolean hasCollection = false;
for (Object o : l) {
    if (o instanceof Collection) {
        hasCollection = true;
        break;
if (!hasCollection && (l instanceof List)) {
...
Listflatten(Collection list, Class type)
flatten
List<Object> retVal = new ArrayList<Object>();
flatten(list, retVal);
return (List<T>) retVal;
Listflatten(Collection> nestedList)
combines all the lists in a collection to a single list
List<T> result = new ArrayList<T>();
for (List<T> list : nestedList) {
    result.addAll(list);
return result;
Listflatten(Collection> collOfLists)
This method is NOT intended as a part of public API and should not be used outside the library!
List<U> res = new ArrayList<U>();
for (List<U> l : collOfLists) {
    res.addAll(l);
return res;
Stringflatten(Collection collection, char separator)
flatten
StringBuilder buf = new StringBuilder(""); 
if (!isEmptyCollection(collection)) {
    Iterator<T> iter = collection.iterator();
    buf.append(String.valueOf(iter.next()));
    while (iter.hasNext()) {
        buf.append(separator).append(String.valueOf(iter.next()));
return buf.toString();
Collectionflatten(Collection original)
flatten
boolean hasNested = false;
for (Object o : original) {
    if (o instanceof Collection) {
        hasNested = true;
        break;
if (!hasNested)
...