Java Collection Flatten flatten(Collection> cols)

Here you can find the source of flatten(Collection> cols)

Description

flatten

License

Apache License

Declaration

public static <V> Collection<V> flatten(Collection<? extends Collection<V>> cols) 

Method Source Code

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

import java.util.*;

public class Main {
    public static <V> Collection<V> flatten(Collection<? extends Collection<V>> cols) {
        if (cols.size() == 0) {
            return Collections.emptyList();
        } else if (cols.size() == 1) {
            return cols.iterator().next();
        } else {//w  w  w.  j  a  v a2  s.co m
            Collection<V> result = new ArrayList<V>();
            for (Collection<V> c : cols) {
                for (V v : c) {
                    result.add(v);
                }
            }
            return result;
        }
    }
}

Related

  1. flatten( Collection colOfCols)
  2. flatten(Class cls, Collection> collections)
  3. flatten(Collection> collections)
  4. flatten(Collection l)
  5. flatten(Collection list, Class type)
  6. flatten(Collection> nestedList)
  7. flatten(Collection> collOfLists)