See the documentation of List#contains given below:
Returns true if this list contains the specified element. More
formally, returns true if and only if this list contains at least one
element e such that Objects.equals(o, e).
Thus, you need to override equals
method in class City
. You can do it as follows:
@Override
public boolean equals(Object obj) {
City other = (City) obj;
return Objects.equals(name, other.name) && Objects.equals(country, other.country);
}
0
solved Why is .contains returning false when I add a duplicate? [closed]