Here you can find the source of flatten(Collection extends Collection
public static <V> Collection<V> flatten(Collection<? extends Collection<V>> cols)
//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; } } }