Java List Union Union(List A, List B)

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

Description

Union

License

Open Source License

Declaration

public static List Union(List A, List B) 

Method Source Code

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

Related

  1. union(final List list1, final List list2)
  2. union(final List list1, final List list2)
  3. union(final List list1, final List list2)
  4. union(final List list1, final List list2)
  5. union(final List... lists)
  6. union(List ls, List ls2)
  7. union(List byteList)
  8. union(List list1, List list2, boolean duplicate)
  9. union(List set1, List set2)