Java Collection Convert toHashSet(Collection c)

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

Description

to Hash Set

License

Apache License

Declaration

public static <T> Set<T> toHashSet(Collection<T> c) 

Method Source Code

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

import java.util.*;

public class Main {
    public static <T> Set<T> toHashSet(Collection<T> c) {
        if (isEmpty(c)) {
            return null;
        }//from  w w  w  .j a  v a  2 s.  co m
        Set<T> set = new HashSet<T>(c.size() * 2);
        set.addAll(c);
        return set;
    }

    public static boolean isEmpty(Collection<?> list) {
        return list == null || list.isEmpty();
    }
}

Related

  1. toDelimitedString(final Collection coll, final String delim)
  2. toDoubles(Collection numbers)
  3. toEnumeration(final Collection collection)
  4. toEscapedStringWithDelimiters(Collection objects, String delim)
  5. toggleEntry(T entry, Collection collection)
  6. toHtml(Collection collection)
  7. toIntegerCollection(int[] ints)
  8. toJSONString(Collection collection)
  9. tokenSetString(Collection tokens)