I have many classes that implement a common interface. I use a definition like Array List mytypes, and add objects of that type to the ArrayList. Now i want to use contains method of the ArrayList class to see if this List contains a class i am adding.
If I implement hashcode and equals on the classes will the contains method know if a certain object already is in the ArrayList or not?
ArrayList.containswon’t usehashCode, but it will useequals, as documented:(This won’t check whether “this class” is already in the list – it will check whether an equal object is in the list.)