Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing data in an Object arrayList  RSS feed

 
Jason Rod
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question about Object arrayLists. I populated an arrayList with data and then wrote the ArrayList to disk using an ObjectOutputStream. I then repopulated the ArrayList using an ObjectInputStream but I am having trouble accessing this data and was wondering if anyone can help me out or point me in a general direction. I've tried using the ".indexOf(Object elem) method but it returned "-1" when I know the data is in there. I've already looked at all the information listed on the Java website and it didn't help at all. Thanks in advance for the help.
 
David McCombs
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you know it is there? If it was there it would not have returned -1 Did you try printing the list?

Post your code.
 
Jason Rod
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have checked and double checked the file which I am reading from and it has the element in there. Here is my code:



I used a JOP to print out the ArrayList.toString() method and the element I am trying to access is in there too.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you overridden equals() for the class of objects you have stored in the ArrayList?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!