To add element to HashSet in Java
hashSet.add(object);
Full source
import java.util.HashSet; public class Main { public static void main(String args[]) { // Create a hash set. HashSet<String> hs = new HashSet<String>(); /*from w w w.j ava2 s . c o m*/ // Add elements to the hash set. hs.add("CSS"); hs.add("HTML"); hs.add("Java"); hs.add("Javascript"); hs.add("SQL"); hs.add("demo2s.com"); System.out.println(hs); } }