Here you can find the source of getIntersection( final Collection extends Collection extends Object>> collections)
Parameter | Description |
---|---|
collections | a parameter |
public static Collection<?> getIntersection( final Collection<? extends Collection<? extends Object>> collections)
//package com.java2s; /******************************************************************************* * Manchester Centre for Integrative Systems Biology * University of Manchester//w ww . j av a2 s. c o m * Manchester M1 7ND * United Kingdom * * Copyright (C) 2007 University of Manchester * * This program is released under the Academic Free License ("AFL") v3.0. * (http://www.opensource.org/licenses/academic.php) *******************************************************************************/ import java.util.*; public class Main { /** * * @param collections * @return Collection */ public static Collection<?> getIntersection( final Collection<? extends Collection<? extends Object>> collections) { final List<Collection<?>> collectionsList = new ArrayList<Collection<?>>(collections); final Collection<Object> intersection = new HashSet<>(); if (collectionsList.size() != 0) { intersection.addAll(collectionsList.get(0)); } for (int i = 1; i < collections.size() && intersection.size() > 0; i++) { intersection.retainAll(new HashSet<>(collectionsList.get(i))); } return intersection; } }