Will Serialization change sort order?

Discussion in 'Java' started by timasmith, May 1, 2006.

  1. timasmith

    timasmith Guest

    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
     
    timasmith, May 1, 2006
    #1
    1. Advertisements

  2. 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.
     
    Mike Schilling, May 1, 2006
    #2
    1. Advertisements

  3. timasmith

    Daniel Dyer Guest

    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.
     
    Daniel Dyer, May 1, 2006
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.