Java List Value Add add(List current, T toAdd)

Here you can find the source of add(List current, T toAdd)

Description

Generic addition of an item to a List (without repeats) -- used to accommodate ObservableLists in front-end

License

Open Source License

Parameter

Parameter Description
current a parameter
toAdd a parameter

Declaration

public static <T> void add(List<T> current, T toAdd) 

Method Source Code


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

import java.util.List;

public class Main {
    /**/*from   w w  w  .  j ava 2  s .co m*/
     * Generic addition of an item to a List (without repeats) -- used to
     * accommodate ObservableLists in front-end
     * 
     * @param current
     * @param toAdd
     */
    public static <T> void add(List<T> current, T toAdd) {
        for (int i = 0; i < current.size(); i++) {
            if (current.get(i).equals(toAdd)) {
                current.remove(i);
                i--;
            }
        }
        current.add(toAdd);
    }
}

Related

  1. add(List> target, E value)
  2. add(List a, List b)
  3. add(List list, String value)
  4. add(List aList, T anObj)
  5. add(List aList, T anObject)
  6. add(List list, int i, T v)
  7. add(List list, T element)
  8. add(Map> multiValueMap, String key, Object value)
  9. add(Object o, List oldList)