Java HashSet(int initialCapacity, float loadFactor) Constructor

Syntax

HashSet(int initialCapacity, float loadFactor) constructor from HashSet has the following syntax.

public HashSet(int initialCapacity,  float loadFactor)

Example

In the following code shows how to use HashSet.HashSet(int initialCapacity, float loadFactor) constructor.


import java.util.HashSet;
//from w  w  w.j a  v a2s.  c  om
public class Main{
    public static void main(String args[]) {
        HashSet<String> hs = new HashSet<String>(20,0.75F);

        hs.add("java2s.com");
        hs.add("j a v a2s.com");

        System.out.println(hs);
    }
}

The code above generates the following result.