Here you can find the source of Intersect(List A, List B)
public static List Intersect(List A, List B)
//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; } }