Re: Array objects get changed when sorting the array

Discussion in 'Java' started by Roedy Green, Jun 25, 2009.

  1. Roedy Green

    Roedy Green Guest

    On Thu, 25 Jun 2009 08:39:43 -0700 (PDT), Christian
    <> wrote, quoted or indirectly quoted
    someone who said :

    >In both cases, when sorting the array, afterwards some of the elements
    >are like reset, they contain only default values. E.g. the array
    >contains 27 elements. None of the elements entirely contains default
    >values anymore. One or the other property is always set to another
    >value. After the sort it still contains 27 elements, but the first 4
    >items contain only default values. The remaining 23 elements still
    >have all their property values and are sorted properly.


    All that happens during as sort is the compareTo method gets called.
    Presumably your compareTo method is under some circumstances modifying
    the fields. See http://mindprod.com/applet/comparatorcutter.html for a
    little program to generate you the Comparable or Comparator code.

    To analyse just what you did wrong, we need as SSCCE. See
    http://mindprod.com/jgloss/sscce.html

    --
    Roedy Green Canadian Mind Products
    http://mindprod.com

    If everyone lived the way people do in Vancouver, we would need three more entire planets to support us.
    ~ Guy Dauncey
    Roedy Green, Jun 25, 2009
    #1
    1. Advertising

  2. Roedy Green

    Roedy Green Guest

    On Thu, 25 Jun 2009 12:02:28 -0700, Roedy Green
    <> wrote, quoted or indirectly quoted
    someone who said :

    >To analyse just what you did wrong, we need as SSCCE. See
    >http://mindprod.com/jgloss/sscce.html


    If you want to solve this with without writing an sscce, instrument a
    setter with some debug code. have it dump a stack trace. See
    http://mindprod.com/jgloss/stacktrace.html
    Make sure all changes to that field go through the setter.

    Then you can find out just when the corruption is happening, and the
    call chain that did it. It may well be something that happens before
    or after the sort.
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com

    If everyone lived the way people do in Vancouver, we would need three more entire planets to support us.
    ~ Guy Dauncey
    Roedy Green, Jun 25, 2009
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    679
    Rosanne
    Oct 11, 2005
  2. 7stud
    Replies:
    11
    Views:
    684
    Dennis Lee Bieber
    Mar 20, 2007
  3. markspace
    Replies:
    1
    Views:
    386
    markspace
    Jun 25, 2009
  4. jdn

    Sorting DataGrid after Row Data Changed

    jdn, Nov 15, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    120
  5. mxbrunet
    Replies:
    1
    Views:
    210
Loading...

Share This Page