• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

static final int[] wont print unsorted column

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry to post the whole class, but I don't know how to reduce this correctly. The problem is the printSortedScreen method, which is supposed to print the unsorted column first, then the sorted column, but it actually prints both columns sorted. I don't know what I've done wrong..

 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is with this method



The first parameter is an object reference. When you sort the array named toSort inside the method, it sorts the array referred to by the parameter you send.

What you need to do is something like create a temporary array inside the method and copy the contents of the array to be sorted into it. Then sort that array instead of the array referred to by toSort.

Making the array reference final does not prevent the elements in the array from being changed. It prevents the array name from pointing to another array.

For example, this works with no problem



, but this causes a compile-time error.


[ February 17, 2006: Message edited by: Keith Lynn ]
 
Jesse Crockett
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My heart is broken that final doesn't work the way I thought. But of course it doesn't, no matter how much I say "but I *did* push the jump button"


[ February 17, 2006: Message edited by: Jesse Crockett ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic