private static class Coord {
public int x, y;
public Coord(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public boolean equals(Object o) {
if (this.getClass() != o.getClass()) return false;
Coord c = (Coord) o;
return this.x == c.x && this.y == c.y;
}
HashSet<Coord> set = new HashSet<>();
set.add(new Coord(1, 1));
set.add(new Coord(1, 1));
System.out.println(set.size()) // 2 is outputed
The docs say that it runs .equals on them