Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

Will Serialization change sort order?

Thread view: 
timasmith@hotmail.com - 01 May 2006 03:51 GMT
I am noticiing some inconsitencies but cant pin them down.  Perhaps the
answer to this question can help.

If I have a vector of objects which on the server side I executed
 Collections.sort(vector);

I then sent the vector over the network to the client (serialized I
assume).

Will the sort order be guaranteed to be the same in the Vector?

or should I always sort on the other end...?

thanks

Tim
Mike Schilling - 01 May 2006 07:31 GMT
>I am noticiing some inconsitencies but cant pin them down.  Perhaps the
> answer to this question can help.
[quoted text clipped - 8 lines]
>
> or should I always sort on the other end...?

Serialization and deserialization will not change the order of objects in a
vector.

However, depending on what criteria you use to sort the items, perhaps they
should be in a different order in the two processes.  For instance, if you
sort Objects by the value of their hashCode(), this will almost certainly
give different results.  If you sort Strings and the two processes have
different default locales, that might result in differences as well.
Daniel Dyer - 01 May 2006 12:05 GMT
> I am noticiing some inconsitencies but cant pin them down.  Perhaps the
> answer to this question can help.
[quoted text clipped - 8 lines]
>
> or should I always sort on the other end...?

A Vector is a List (java.util.List), which, unlike a Set, guarantees the  
order of its elements.  So if the order is not the same after  
serialisation/deserialisation, then something is broken.

Dan.

Signature

Daniel Dyer
http://www.dandyer.co.uk



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.