I have this class point
class Point
{
private int x;
private int y;
Point(int x, int y)
{
this.x = x;
this.y = y;
}
public int getX()
{
return x;
}
public int getY()
{
return y;
}
public int hashCode()
{
return this.toString().hashCode();
}
public String toString()
{
return ("[" + x + ", " + y + "]");
}
public boolean equals(Point point)
{
return (this.x == point.getX() && this.y == point.getY());
}
}
and when I try to make HashSets with them the sets end up with duplicate entries.
I tried creating a .hashCode() method but it didn't appear to work
I also tried adding an equals method and it still didn't work
Edit:
changing the equals() method to
public boolean equals(Object o)
{
return (this.toString().equals(o.toString()));
}
fixed it