Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #1175
| Date | 2011-09-30 16:58 -0700 |
|---|---|
| From | Patricia Shanahan <pats@acm.org> |
| Newsgroups | comp.lang.java.help |
| Subject | Re: Reverse sorting an array |
| References | <8ea2add1-ce9c-423b-bdb8-92c461cf9c6d@5g2000yqo.googlegroups.com> <j64aek$23e$1@dont-email.me> <2b9bc8c9-d6de-431f-8753-fe9d400e9b1b@n36g2000yqb.googlegroups.com> <4ihc87545r018lbbk02ggp21abgngho21n@4ax.com> <7c66f3a8-c02b-4b5a-b62e-f0561378bfec@b6g2000vbz.googlegroups.com> |
| Message-ID | <l9adnVQkX7s9yhvTnZ2dnUVZ_vydnZ2d@earthlink.com> (permalink) |
On 9/30/2011 4:27 PM, Fred wrote: > But I must be missing something obvious here - why does this print > zeroes? ... > printArray(positives, positivesIndex); > Arrays.sort(positives); > printArray(positives, positivesIndex); ... Arrays.sort without a specified fromIndex and toIndex sorts the entire array. I would expect to see (positives.length - positivesIndex) zero elements before the first positive element in the sorted array. Given the facts that you are reading a variable number of elements and you need to do reverse sorting, are you *sure* you should be working with int rather than Integer? If you used Integer, you could build up a List exactly the right length, avoiding any extra zero elements. You could use Collections.sort with the Collections.reverseOrder() comparator to directly sort them in descending order. The whole thing would be simpler. At least so far, you are not doing any arithmetic that would need int, and you don't have anywhere near enough elements for there to be a significant performance difference. Patricia
Back to comp.lang.java.help | Previous | Next — Previous in thread | Next in thread | Find similar
Reverse sorting an array Fred <albert.xtheunknown0@gmail.com> - 2011-09-30 04:03 -0700
Re: Reverse sorting an array Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-30 07:50 -0400
Re: Reverse sorting an array Fred <albert.xtheunknown0@gmail.com> - 2011-09-30 15:24 -0700
Re: Reverse sorting an array Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-30 20:50 -0400
Re: Reverse sorting an array Roedy Green <see_website@mindprod.com.invalid> - 2011-10-01 19:38 -0700
Re: Reverse sorting an array Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-10-01 22:58 -0400
Re: Reverse sorting an array Lew <lewbloch@gmail.com> - 2011-10-01 20:21 -0700
Re: Reverse sorting an array Fred <albert.xtheunknown0@gmail.com> - 2011-09-30 15:31 -0700
Re: Reverse sorting an array Roedy Green <see_website@mindprod.com.invalid> - 2011-09-30 15:45 -0700
Re: Reverse sorting an array Fred <albert.xtheunknown0@gmail.com> - 2011-09-30 16:27 -0700
Re: Reverse sorting an array Patricia Shanahan <pats@acm.org> - 2011-09-30 16:58 -0700
Re: Reverse sorting an array Roedy Green <see_website@mindprod.com.invalid> - 2011-09-30 15:43 -0700
Re: Reverse sorting an array Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-30 20:57 -0400
Re: Reverse sorting an array Roedy Green <see_website@mindprod.com.invalid> - 2011-09-30 04:58 -0700
What qualifies as a constant ? (Was: Reverse sorting an array) Mayeul <mayeul.marguet@free.fr> - 2011-09-30 14:45 +0200
Re: What qualifies as a constant ? (Was: Reverse sorting an array) Lew <lewbloch@gmail.com> - 2011-09-30 07:39 -0700
Re: What qualifies as a constant ? (Was: Reverse sorting an array) Mayeul <mayeul.marguet@free.fr> - 2011-09-30 17:15 +0200
Re: What qualifies as a constant ? (Was: Reverse sorting an array) Lew <lewbloch@gmail.com> - 2011-09-30 08:42 -0700
csiph-web