Java List Intersect getIntersection( final List... collectionOfIDLists)

Here you can find the source of getIntersection( final List... collectionOfIDLists)

Description

Returns the common elements of several Integer-Lists.

License

Open Source License

Parameter

Parameter Description
collectionOfIDLists a parameter

Return

common elements of lists

Declaration

public static List<Integer> getIntersection(
        final List<Integer>... collectionOfIDLists) 

Method Source Code

//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;
    }
}

Related

  1. calcIntersection(List a, List b)
  2. calculauteIntersection(Set wordList1, Set wordList2)
  3. getIntersection(List list1, List list2)
  4. getIntersection(String[] list1, String[] list2)
  5. getIntersectionOfLineAndSegments(double x1, double y1, double x2, double y2, List segmentPoints)
  6. hasIntersection(List list1, List list2)