Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #1162
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Newsgroups | comp.lang.java.help |
| Subject | Re: Reverse sorting an array |
| Date | 2011-09-30 04:58 -0700 |
| Organization | Canadian Mind Products |
| Message-ID | <0tab87dkpjalvsqde3v720ap8h8pa8l2or@4ax.com> (permalink) |
| References | <8ea2add1-ce9c-423b-bdb8-92c461cf9c6d@5g2000yqo.googlegroups.com> |
On Fri, 30 Sep 2011 04:03:01 -0700 (PDT), Fred
<albert.xtheunknown0@gmail.com> wrote, quoted or indirectly quoted
someone who said :
>import java.util.*;
>
>class InputCounter {
> public static void main(String[] args) {
> final int MAX_NUMBERS = 50;
> int[] array = new int[MAX_NUMBERS];
> Arrays.sort(array, Collections.reverseOrder());
> }
>}
see http://mindprod.com/jgloss/sort.html for a example of how to sort
an array and how to use Collections.reverseOrder.
MAX_NUMBERS is not a constant (static final) so should not be
capitalised. Alternatively, make it a static final.
Your probelm is that reverseOrder is only for sorting Objects in
reverse order. Arrays.sort does not support Comparators or
reverseOrder, except for Objects. You can't sort an array of primitive
int is reverse order.
I compiled your program and was swamped with errors:
InputCounter.java:7: error: no suitable method found for
sort(int[],Comparator<Object>)
Arrays.sort(array, Collections.reverseOrder());
^
method Arrays.<T#1>sort(T#1[],int,int,Comparator<? super T#1>) is
not applicable
(cannot instantiate from arguments because actual and formal
argument lists differ in length)
method Arrays.<T#2>sort(T#2[],Comparator<? super T#2>) is not
applicable
(no instance(s) of type variable(s) T#2 exist so that argument
type Comparator<Object> conform
s to formal parameter type Comparator<? super T#2>)
method Arrays.sort(Object[],int,int) is not applicable
(actual and formal argument lists differ in length)
method Arrays.sort(Object[]) is not applicable
(actual and formal argument lists differ in length)
method Arrays.sort(double[],int,int) is not applicable
(actual and formal argument lists differ in length)
method Arrays.sort(double[]) is not applicable
(actual and formal argument lists differ in length)
method Arrays.sort(float[],int,int) is not applicable
(actual and formal argument lists differ in length)
method Arrays.sort(float[]) is not applicable
(actual and formal argument lists differ in length)
method Arrays.sort(byte[],int,int) is not applicable
(actual and formal argument lists differ in length)
method Arrays.sort(byte[]) is not applicable
(actual and formal argument lists differ in length)
method Arrays.sort(char[],int,int) is not applicable
(actual and formal argument lists differ in length)
method Arrays.sort(char[]) is not applicable
(actual and formal argument lists differ in length)
method Arrays.sort(short[],int,int) is not applicable
(actual and formal argument lists differ in length)
method Arrays.sort(short[]) is not applicable
(actual and formal argument lists differ in length)
method Arrays.sort(long[],int,int) is not applicable
(actual and formal argument lists differ in length)
method Arrays.sort(long[]) is not applicable
(actual and formal argument lists differ in length)
method Arrays.sort(int[],int,int) is not applicable
(actual and formal argument lists differ in length)
method Arrays.sort(int[]) is not applicable
(actual and formal argument lists differ in length)
where T#1,T#2 are type-variables:
T#1 extends Object declared in method
<T#1>sort(T#1[],int,int,Comparator<? super T#1>)
T#2 extends Object declared in method <T#2>sort(T#2[],Comparator<?
super T#2>)
1 error
--
Roedy Green Canadian Mind Products
http://mindprod.com
It should not be considered an error when the user starts something
already started or stops something already stopped. This applies
to browsers, services, editors... It is inexcusable to
punish the user by requiring some elaborate sequence to atone,
e.g. open the task editor, find and kill some processes.
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