To simplify, let's say I have arraylist allBooksa class containing a “book” and arraylist someBookscontaining some, but not all, “books”.
Using the contains () method worked fine when I wanted to see if the book contained a book from one arraylist.
The problem was that this no longer works when I save both Arraylists in a .bin file and load them after the program is reloaded. Performing the same test as before, the contains () function returns false, even if the objects being compared are the same (have the same information inside).
I solved this by overloading the equals method and it works fine, but I want to know why this happened?
source
share