Here you can find the source of getIntersection( final List
Parameter | Description |
---|---|
collectionOfIDLists | a parameter |
public static List<Integer> getIntersection( final List<Integer>... collectionOfIDLists)
//package com.java2s; import java.util.ArrayList; import java.util.List; public class Main { /**// w w w . j a v a 2 s . co m * Returns the common elements of several Integer-Lists. * * @param collectionOfIDLists * @return common elements of lists */ public static List<Integer> getIntersection( final List<Integer>... collectionOfIDLists) { if (collectionOfIDLists == null || collectionOfIDLists.length == 0) { return new ArrayList<Integer>(); } final List<List<Integer>> copyListOfIDLists = new ArrayList<List<Integer>>(); for (final List<Integer> list : collectionOfIDLists) { copyListOfIDLists.add(new ArrayList<Integer>(list)); } final List<Integer> retainedIDs = copyListOfIDLists.get(0); if (retainedIDs.isEmpty()) { return retainedIDs; } for (final List<Integer> list : copyListOfIDLists) { retainedIDs.retainAll(list); } return retainedIDs; } }