Java Collection Tutorial - Java HashSet() Constructor








Syntax

HashSet() constructor from HashSet has the following syntax.

public HashSet()

Example

In the following code shows how to use HashSet.HashSet() constructor.

//from   w  ww  .  j av  a 2  s .  co m
import java.util.HashSet;

public class Main{
    public static void main(String args[]) {
        HashSet<String> hs = new HashSet<String>();


        System.out.println(hs.isEmpty());
    }
}
  

The code above generates the following result.