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

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

Method Source Code

//package com.java2s;

import java.util.List;

public class Main {
    static public <T> void addUnique(List<T> list, T item) {
        if (isInList(list, item) == null) {
            list.add(item);//w ww.jav  a2 s. c  o m
        }
    }

    static public <T> T isInList(List<T> list, T item) {
        for (T elm : list) {
            if (elm.equals(item)) {
                return elm;
            }
        }
        return null;
    }
}

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