We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › sort() on multidimensional arrays
Page Index Toggle Pages: 1
sort() on multidimensional arrays? (Read 580 times)
sort() on multidimensional arrays?
Aug 4th, 2009, 9:51am
 
Hi,

it looks like sort() does work on 1-dimensional arrays (lists) only.

What I would like to achieve is to sort the columns of one row, and have the other columns sorted accordingly, e.g.

Unsorted 2x3 array:

row1: "B","C","A"
row2: "X","Y","Z"

sorting row1 --> result:

row1: "A","B","C"
row2: "Z","X","Y"

Of course I could use a HashMap that associates the column values in row 1 and 2.

The Processing Reference states String[], int[], or float[] als possible parameters for sort().
A solution would be also if sort() accepted Objects.

Or is there any available Java class that allows advanced sorting?

(Another workaround for me would be to apply sorting on the data before it is imported into the Processing code).
Re: sort() on multidimensional arrays?
Reply #1 - Aug 4th, 2009, 4:08pm
 
mbs wrote on Aug 4th, 2009, 9:51am:
A solution would be also if sort() accepted Objects.

Or is there any available Java class that allows advanced sorting

Yes. See Arrays.sort and Comparable or the other Arrays.sort and Comparator.
Re: sort() on multidimensional arrays?
Reply #2 - Aug 5th, 2009, 2:31am
 
Thank you.
Page Index Toggle Pages: 1