Java List Add Unique addUnique(List list, T item)

Here you can find the source of addUnique(List list, T item)

Description

add Unique

License

Open Source License

Declaration

public static <T> boolean addUnique(List<T> list, T item) 

Method Source Code

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

import java.util.List;

public class Main {

    public static <T> boolean addUnique(List<T> list, T item) {
        if (!list.contains(item)) {
            list.add(item);//  w w w  . j a v a2  s. co  m
            return true;
        } else {
            return false;
        }
    }
}

Related

  1. addUniq(List list, Object object)
  2. addUnique(java.util.List l, String e)
  3. addUnique(List aList, T anObj)
  4. addUnique(List list, T item)
  5. addUniqueId(List aList, T anObj)
  6. addUniqueItems(List from, List to)
  7. addUniqueValues(List source, List target)

  8. HOME | Copyright © www.java2s.com 2016