Java List Value Add All addAllUniqueToList(List objects, List objectsToAdd)

Here you can find the source of addAllUniqueToList(List objects, List objectsToAdd)

Description

add All Unique To List

License

Open Source License

Declaration

public static List addAllUniqueToList(List objects, List objectsToAdd) 

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./*from   w  ww  .jav  a2  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.List;

public class Main {
    public static List addAllUniqueToList(List objects, List objectsToAdd) {
        if (objectsToAdd == null) {
            return objects;
        }
        int size = objectsToAdd.size();
        for (int index = 0; index < size; index++) {
            Object element = objectsToAdd.get(index);
            if (!objects.contains(element)) {
                objects.add(element);
            }
        }
        return objects;
    }
}

Related

  1. addAllToANewList(Collection... collections)
  2. addAllToList(List dest, Collection src)
  3. addAllUnique(List aList, List theObjects)
  4. addAllUnique(List l1, T element)
  5. addAllUniqueId(List aList, List theObjects)
  6. addAllWords(String text, List result)
  7. addArrayToList(List list, String as[])
  8. addArrayToList(List list, double[] array)
  9. addArrayToList(List list, T[] array)