fork(1) download
  1.  
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class MyBasicHashSet {
  8.  
  9. public static void main(String a[]){
  10. HashSet<String> hs = new HashSet<String>();
  11. //add elements to HashSet
  12. hs.add("first");
  13. hs.add("second");
  14. hs.add("third");
  15. System.out.println(hs);
  16. System.out.println("Is HashSet empty? "+hs.isEmpty());
  17. hs.remove("third");
  18. System.out.println(hs);
  19. System.out.println("Size of the HashSet: "+hs.size());
  20. System.out.println("Does HashSet contains first element? "+hs.contains("first"));
  21. }
  22. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
[third, first, second]
Is HashSet empty? false
[first, second]
Size of the HashSet: 2
Does HashSet contains first element? true