Java Utililty Methods List Uniqne Item

List of utility methods to do List Uniqne Item

Description

The list of methods to do List Uniqne Item are organized into topic(s).

Method

Listunique(List array)
unique
if (array == null)
    throw new NullPointerException("Not initizalize array");
List<E> uniq = new ArrayList<E>();
HashMap<E, Boolean> visited = new HashMap<E, Boolean>();
for (E s : array) {
    if (!visited.containsKey(s)) {
        uniq.add(s);
        visited.put(s, true);
...
ENTITYunique(List entities)
Gets from a entity list the unique entity expected.
if (entities.isEmpty()) {
    return null;
if (entities.size() == 1) {
    return entities.get(0);
throw new IllegalArgumentException(
        "wanted to get a unique entity from a list that contains more than one...");
...
Listunique(List list)
unique
if (list.size() < 2) {
    return list;
List<T> sorted = new LinkedList<T>(list);
Collections.sort(sorted);
T current = sorted.get(sorted.size() - 1);
for (int i = sorted.size() - 1; i > 0; i--) {
    T previous = sorted.get(i - 1);
...
Collection

uniqueList(Collection

list)
Remove all duplicated entries.

ArrayList<P> uniqueList = new ArrayList<>();
for (P item : list) {
    if (uniqueList.contains(item)) {
        continue;
    uniqueList.add(item);
return uniqueList;
...
ListuniqueList(List list)
Make a copy of a list where the items are unique.
if (list == null) {
    return null;
List<T> unique = new ArrayList<T>(list.size());
for (T next : list) {
    if (!unique.contains(next)) {
        unique.add(next);
return unique;
ListuniqueListInsert(List list1, List list2)
Inserts the elements of a List into another List making sure not to duplicate entries in the resulting List
if (list2 != null) {
    for (String fromList2 : list2) {
        if (!list1.contains(fromList2) && (!"#".equals(fromList2))) {
            list1.add(fromList2);
return list1;
...
booleanuniqueMacTest(List macs, String attempt)
unique Mac Test
for (Object mac1 : macs) {
    final String mac = (String) mac1;
    if (attempt.equals(mac)) {
        return false;
return true;