• Home
  • LLMs
  • Python
  • Docker
  • Kubernetes
  • Java
  • Maven
  • All
  • About
Java | HashSet
  1. Notes
  2. Example

  1. Notes
    Unsorted collection
    Unordered collection
    null elements allowed
    Duplicates elements not allowed (hash code)
  2. Example
    HashSet<String> hs = new HashSet<>();
    
    hs.add(null);
    hs.add("aaa");
    hs.add("aaa");
    hs.add("aaa");
    hs.add("bbb");
    hs.add("bbb");
    hs.add("ccc");
    
    hs.forEach(System.out::println);
    Output:
    null
    aaa
    ccc
    bbb
© 2025  mtitek