hashset.add java code example
Example 1: HashSet add(E e) method in java
import java.util.HashSet;
public class HashSetAddMethodExample
{
public static void main(String[] args)
{
HashSet<String> hs = new HashSet<String>();
hs.add("violet");
hs.add("indigo");
hs.add("blue");
hs.add("green");
hs.add("yellow");
System.out.println("HashSet of colors: " + hs);
}
}
Example 2: how to push an element in hashset java
HashSet<Integer> set=new HashSet<>();
set.add(10);
Example 3: java hashset
HashSet<String> hset = new HashSet<String>();
hset.add("Apple");
hset.add("Mango");