Java List Intersect Intersect(List A, List B)

Here you can find the source of Intersect(List A, List B)

Description

Intersect

License

Open Source License

Declaration

public static List Intersect(List A, List B) 

Method Source Code

//package com.java2s;
/**********************************************************************
 * Copyright (c) 2007 IBM Corporation./*from ww w.j av  a 2  s  .c  o m*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Main {
    public static List Intersect(List A, List B) {
        if (A == null || B == null)
            return null;
        List list = new ArrayList();
        for (Iterator i = A.iterator(); i.hasNext();) {
            Object o = i.next();
            if (B.contains(o))
                list.add(o);
        }
        return list;
    }
}

Related

  1. getIntersection(List list1, List list2)
  2. getIntersection(String[] list1, String[] list2)
  3. getIntersectionOfLineAndSegments(double x1, double y1, double x2, double y2, List segmentPoints)
  4. hasIntersection(List list1, List list2)
  5. hasIntersection(Set set, List list)
  6. intersect(List ls, List ls2)
  7. intersect(List lst1, List lst2)
  8. intersect(List list1, List list2)
  9. intersect(List... lists)