HashSet in Java — a practical guide to Java HashSet with clear examples you can reuse in real projects.
Java Tutorial Series (53/90). Prefer one article? Read the complete Java tutorial.
Short description
`HashSet` ignores duplicates and offers average O(1) add/contains.
HashSet
import java.util.HashSet;
HashSet<Integer> set = new HashSet<>();
set.add(1);
set.add(1);
System.out.println(set.size()); // 1