Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Index in serialized Collection

 
Pablo Vilas
Greenhorn
Posts: 5
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

if I serialize a class that contains a collection, that guarantee the object index don´t change between serialization and deserialization?

Thank you.
 
Paul Clapham
Sheriff
Pie
Posts: 20955
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's an "object index"?
 
Mike Simmons
Ranch Hand
Posts: 3038
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pablo, it depends on the collection. If you've got some sort of serializable List (like ArrayList or LinkedList), then each entry in the List has an index, and the value of that index will not change when you serialize and deserialize the List. However if you've got some other collection, like a HashSet, there is no notion of an index, and there is not necessarily any guarantee that the elements will be observed in the same order (e.g. if you iterate through the collection).
 
Pablo Vilas
Greenhorn
Posts: 5
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:What's an "object index"?


The index of an object inside a List. Sorry about my English
 
Pablo Vilas
Greenhorn
Posts: 5
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Simmons wrote:Pablo, it depends on the collection. If you've got some sort of serializable List (like ArrayList or LinkedList), then each entry in the List has an index, and the value of that index will not change when you serialize and deserialize the List. However if you've got some other collection, like a HashSet, there is no notion of an index, and there is not necessarily any guarantee that the elements will be observed in the same order (e.g. if you iterate through the collection).


Thank you very much Mike. I shall use an Arraylist.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic