Here you can find the source of Union(List A, List B)
public static List Union(List A, List B)
//package com.java2s; /********************************************************************** * Copyright (c) 2007 IBM Corporation.//from w ww.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 Union(List A, List B) { if (A == null) return B; if (B == null) return A; List list = new ArrayList(A); for (Iterator i = B.iterator(); i.hasNext();) { Object o = i.next(); if (!list.contains(o)) list.add(o); } return list; } public static List Union(List A, List B, List C) { return Union(Union(A, B), C); } }