Here you can find the source of intersection( Collection extends Collection extends T>> coll)
Parameter | Description |
---|---|
coll | A Collection of sets |
public static <T> Set<T> intersection( Collection<? extends Collection<? extends T>> coll)
//package com.java2s; // Clark & Parsia, LLC parts of this source code are available under the terms of the Affero General Public License v3. import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.Set; public class Main { /**/* w w w . j a va 2 s . c o m*/ * Returns the intersection of all the collections given in a collection. * * @param coll A Collection of sets */ public static <T> Set<T> intersection( Collection<? extends Collection<? extends T>> coll) { Iterator<? extends Collection<? extends T>> i = coll.iterator(); if (!i.hasNext()) return new HashSet<T>(); Set<T> set = new HashSet<T>(i.next()); while (i.hasNext()) { Collection<? extends T> innerColl = i.next(); set.retainAll(innerColl); } return set; } /** * Returns the intersection of two collections * * @param coll A Collection of sets */ public static <T> Set<T> intersection(Collection<? extends T> c1, Collection<? extends T> c2) { Set<T> set = new HashSet<T>(c1); set.retainAll(c2); return set; } }