Java List Concatenate concatenateUniqueLists(List first, List second)

Here you can find the source of concatenateUniqueLists(List first, List second)

Description

Return a new List with no duplicated values.

License

Open Source License

Declaration

public static List concatenateUniqueLists(List first, List second) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 1998, 2015 Oracle and/or its affiliates. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
 * which accompanies this distribution./*  w w w. j  a v  a  2  s .c o m*/
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * Contributors:
 *     Oracle - initial API and implementation from Oracle TopLink
 *     dminsky - added countOccurrencesOf(Object, List) API
 *     08/23/2010-2.2 Michael O'Brien
 *        - 323043: application.xml module ordering may cause weaving not to occur causing an NPE.
 *                       warn if expected "_persistence_*_vh" method not found
 *                       instead of throwing NPE during deploy validation.
 ******************************************************************************/

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**
     * Return a new List with no duplicated values.
     */
    public static List concatenateUniqueLists(List first, List second) {
        List concatenation = new ArrayList(first.size() + second.size());
        concatenation.addAll(first);

        for (Object element : second) {
            if (!concatenation.contains(element)) {
                concatenation.add(element);
            }
        }

        return concatenation;

    }
}

Related

  1. concatenateList(List list, String separator)
  2. concatenateListOfStrings(List list, String separator)
  3. concatenateLists(List... lists)
  4. concatenateParameters(List parameters)
  5. concatenateStrings(List strings, String separator)
  6. concatGenericList(List list, String delimiter)
  7. concatinateStrings(List strList, String delim)
  8. concatIntegersToRanges( List damages)
  9. concatLines(List lines)