Arraylist can't compare objects after they are loaded from disk
Posted
by Zka
on Stack Overflow
See other posts from Stack Overflow
or by Zka
Published on 2010-04-26T06:10:59Z
Indexed on
2010/04/26
6:23 UTC
Read the original article
Hit count: 200
To make it easy, lets say I have an arraylist allBooks
containing class "books" and an arraylist someBooks
containing some but not all of the "books".
Using contains() method worked fine when I wanted to see if a book from one arraylist was also contained in another.
The problem was that this isn't working anymore when I save both of the Arraylists to a .bin file and load them back once the program restarts. Doing the same test as before, the contains() returns false even if the compared objects are the same (have the same info inside).
I solved it by overloading the equals method and it works fine, but I want to know why did this happen?
© Stack Overflow or respective owner