Compare by value, not by reference.
HashMap and HashSet use equals() and hashCode(), so a list, a date or your own class works as a key. Plain strings and numbers take a fast path.
Read moreconst seen = new HashSet<List<number>>();seen.add(List.of(1, 2)); // → trueseen.add(List.of(1, 2)); // → falseseen.size(); // → 1