Java Utililty Methods List Add Unique

List of utility methods to do List Add Unique

Description

The list of methods to do List Add Unique are organized into topic(s).

Method

booleanaddUniq(List list, Object object)
add Uniq
if (!list.contains(object))
    return list.add(object);
return false;
voidaddUnique(java.util.List l, String e)
add Unique
if (!l.contains(e)) {
    l.add(e);
ListaddUnique(List aList, T anObj)
Adds an object to the given list if object is absent (creates list if missing).
return contains(aList, anObj) ? aList : add(aList, anObj);
voidaddUnique(List list, T item)
add Unique
if (isInList(list, item) == null) {
    list.add(item);
booleanaddUnique(List list, T item)
add Unique
if (!list.contains(item)) {
    list.add(item);
    return true;
} else {
    return false;
ListaddUniqueId(List aList, T anObj)
Adds an object to the given list if identical object is missing (creates list if missing).
return containsId(aList, anObj) ? aList : add(aList, anObj);
voidaddUniqueItems(List from, List to)
add Unique Items
if (from == null || to == null || from.size() == 0) {
    return;
for (Iterator it = from.iterator(); it.hasNext();) {
    Object o = it.next();
    if (!to.contains(o)) {
        to.add(o);
voidaddUniqueValues(List source, List target)
Adds values from the source list to the target list only if they don't already exist in the target
for (T item : source) {
    if (!target.contains(item)) {
        target.add(item);