• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

arrays sort not works with Comparator

 
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wanna sort pixels by red,green or blue;



Is error:

The method sort(int[]) in the type Arrays is not applicable for the arguments (int[], new Comparator<int[]>(){})

 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The compiler is telling you that Arrays doesn't have a sort method that takes an int[] and a Comparator as parameters. Looking at the documentation, I see that's true.
 
Andrzej Borucki
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is OK if I change to :

Change "int" to "Integer"
Problem: which is difference in memory between int and Integer? If Integer allocates million objects when I initialize pixels = new Integer[1000000] ?
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Andrzej Borucki wrote:Is OK if I change to . . .

No.

You do not need anything to tell whether 3 is greater than 4. If you have an int[] to sort you simply ask the sort method to sort it. No Comparaotr or anything.
 
Andrzej Borucki
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is any method else than Comparator to compare with sort? I must sort by Red or Green or Blue component. If I change int to Integer appears problems with System.arraycopy, array.Clone() etc
 
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Am I correct assuming that you have three separate int arrays, each for one base color?
And you want to sort them all according to one of base colors?
Well, I would use Color class then. And I would sort Color[].
 
Andrzej Borucki
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Three colors are on one integer. There are get from
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're comparing int[]s then your array should be int[][]
 
Andrzej Borucki
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paweł is quite right; you want an array of Colors, not int[] nor byte[]. Color does not implement Comparable, but it has getAlpha getBlue getGreen and getRed methods which can all be used by a Comparator.

And if you tell us you want to sort ints when you actually want to sort Colors, you are going to get unhelpful and confusing answers.
 
reply
    Bookmark Topic Watch Topic
  • New Topic