Java Collection Unique unique(Collection c)

Here you can find the source of unique(Collection c)

Description

unique

License

Apache License

Declaration

public static <T> Collection<T> unique(Collection<T> c) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {

    public static <T> Collection<T> unique(Collection<T> c) {
        if (c != null && c.size() > 0) {
            Map<T, Integer> map = new LinkedHashMap<T, Integer>();
            for (T o : c) {
                map.put(o, 0);//  ww  w.  j a  v  a 2 s.c  o  m
            }
            return new ArrayList<T>(map.keySet());
        }
        return c;
    }
}

Related

  1. getUniqueNameWithNumbers(Collection names, String baseName)
  2. getUniqueValue(Collection values, String initValue)
  3. hasUniqueObject(Collection collection)
  4. hasUniqueObject(Collection collection)
  5. hasUniqueObject(Collection collection)
  6. unique(Collection c, Collection result)
  7. uniqueIdNotIn(String prefix, Collection exclusions)
  8. uniqueResult(Collection results)
  9. uniqueResult(final Collection c)