Java List Value Add addElement(T element, List list)

Here you can find the source of addElement(T element, List list)

Description

add Element

License

Open Source License

Parameter

Parameter Description
element a parameter
list a parameter

Declaration

public static <T> List<T> addElement(T element, List<T> list) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**/*  www.  j  av a  2  s.  com*/
     * @param element
     * @param list
     * @return
     */
    public static <T> List<T> addElement(T element, List<T> list) {
        boolean exists = false;

        if (list == null) {
            list = new ArrayList<T>(2);
        } else {
            exists = list.contains(element);
        }

        if (!exists)
            list.add(element);
        return list;
    }
}

Related

  1. add(List current, T toAdd)
  2. add(List list, int i, T v)
  3. add(List list, T element)
  4. add(Map> multiValueMap, String key, Object value)
  5. add(Object o, List oldList)
  6. addElementIfAbsent(List l, T element)
  7. addElements(boolean removeDuplicates, final List result, Collection elements)
  8. addElements(List list, T[] array)
  9. addElementsIfAbsent(List destList, Collection aColl)