Here you can find the source of toHashSet(Collection
public static <T> Set<T> toHashSet(Collection<T> c)
//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(); } }