Java List Value Add addElementsIfAbsent(List destList, Collection aColl)

Here you can find the source of addElementsIfAbsent(List destList, Collection aColl)

Description

Adds the elements contained in aList that are not already present in the List to the end of the List.

License

Apache License

Parameter

Parameter Description
destList the list to add elements to
aColl a collection of the elements to be added to destList

Declaration

public static <T> void addElementsIfAbsent(List<T> destList, Collection<? extends T> aColl) 

Method Source Code

//package com.java2s;
/*//from   w ww.j av  a 2 s.  com
Copyright 1996-2010 Ariba, Inc.
    
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
    
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
    
$Id: //ariba/platform/util/core/ariba/util/core/ListUtil.java#38 $
*/

import java.util.Collection;

import java.util.Iterator;
import java.util.List;

public class Main {
    /**
    Adds the elements contained in <b>aList</b> that are not already
    present in the List to the end of the List.
    @param destList the list to add elements to
    @param aColl a collection of the elements to be added to destList
        
    @aribaapi documented
    */
    public static <T> void addElementsIfAbsent(List<T> destList, Collection<? extends T> aColl) {
        if (aColl == null) {
            return;
        }

        Iterator<? extends T> i = aColl.iterator();
        while (i.hasNext()) {
            addElementIfAbsent(destList, i.next());
        }
    }

    /**
    Adds <b>element</b> as the last element of the List, if not
    already present within the List.
        
    @param l the List to add to
    @param element the element to add
    @exception NullPointerException if <b>element</b> is <b>null</b>.
    @aribaapi documented
    */
    public static <T> void addElementIfAbsent(List<T> l, T element) {
        if (!l.contains(element)) {
            l.add(element);
        }
    }
}

Related

  1. add(Object o, List oldList)
  2. addElement(T element, List list)
  3. addElementIfAbsent(List l, T element)
  4. addElements(boolean removeDuplicates, final List result, Collection elements)
  5. addElements(List list, T[] array)
  6. appendToList(List list, A elem)
  7. appendToList(List list, T[] elements)