Java List Uniqne Item unique(List array)

Here you can find the source of unique(List array)

Description

unique

License

Open Source License

Declaration

public static <E> List<E> unique(List<E> array) 

Method Source Code

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

import java.util.*;

public class Main {
    public static <E> List<E> unique(List<E> array) {
        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);/*from   w  w  w. ja  v a  2s  . co  m*/
                visited.put(s, true);
            }
        }
        return uniq;
    }
}

Related

  1. unique(List entities)
  2. unique(List list)
  3. uniqueList(Collection

    list)

  4. uniqueList(List list)