Lets say I have a list of objects List<Person> people. This list is composed of multiple Person objects - each has a name and age (and also implements the respective equals and hashCode methods)
The list is populated with multiple (different in memory) objects that are (same in values)
List<Person> people = new ArrayList<>();
Person person_1 = new Person("Tom", 21);
Person person_2 = new Person("Tom", 21);
Person person_3 = new Person("Tom", 21);
person_1.equals(person_2) // true
person_1 == person_2 // false
people.add(person_1);
people.add(person_2);
people.add(person_3);
The problem I have is that people.remove(person_1) removes person_2 and person_3 also.
What can I do to change this?