I have this code for Point class
public class Point {
private int x, y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
}
In other class, inside a method I have
ArrayList<Point> points = new ArrayList<Point>();
Point p = new Point(1, 2);
points.add(p);
Now I want to remove this Point p I just added
Point toRemove = new Point(0, 0);
toRemove.setX(1);
toRemove.setY(2);
points.contains(toRemove);
points.remove(toRemove);
And the contains prints false and the Point is not removed from the ArrayList. How can I remove using an object?