How to create Java HashSet and add value to HashSet - Java Collection Framework

Java examples for Collection Framework:HashSet

Description

How to create Java HashSet and add value to HashSet

Demo Code


import java.util.HashSet;
 
public class Main {
 
  public static void main(String[] args) {
    HashSet hSet = new HashSet();
   //from w w  w. ja  v  a2 s  . c o  m
    hSet.add(new Integer("1"));
    hSet.add(new Integer("2"));
    hSet.add(new Integer("3"));
   
    System.out.println("HashSet contains.." + hSet);  
  }
}

Result


Related Tutorials