Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Index in serialized Collection  RSS feed

 
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
Posts: 22374
42
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: 3090
14
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!