Alphabetize A Matrix Of Words

hey, i have a matrix with a different word ( string ) in each cell. I need those to come out in alphabetical order and i cant think of a way how. Any help? Thanks

Example:

Matrix:

{jon,abby,a

,dave,brian,largo};

and i want it to print

"a abby brian dave jon largo"

I dont need to change the matrix, i just need to get the information out in alphabetical order.

[410 byte] By [concorde18a] at [2007-11-26 12:30:53]
# 1
1) Copy each string from the 2d array into an ArrayList2) Use the Collections.sort(List) method to sort them3) Print the resulting List out.
hunter9000a at 2007-7-7 15:42:09 > top of Java-index,Java Essentials,Java Programming...
# 2

This is part of a really big program that i am not using array lists for. Is there any other way to do it with matricies or do i have to go back and convert everything to arraylists. If thats the case than ill just take the hit of some points because thats gonna take forever. I am done with the whole program and this is the only thing left to do.

concorde18a at 2007-7-7 15:42:09 > top of Java-index,Java Essentials,Java Programming...
# 3
What is your definition of "matrix"? What are the dimensions?
doremifasollatidoa at 2007-7-7 15:42:10 > top of Java-index,Java Essentials,Java Programming...
# 4

> This is part of a really big program that i am not

> using array lists for. Is there any other way to do

> it with matricies or do i have to go back and convert

> everything to arraylists. If thats the case than ill

> just take the hit of some points because thats gonna

> take forever. I am done with the whole program and

> this is the only thing left to do.

You don't have to change the matrices, you're just using the ArrayList to do the sorting for you. Step 1 was copying the values from the matrix into the List; the matrix is unchanged. If all you want to do is print them out alphabatized, then trash the List afterwards. If you want to keep them in sorted order, then hang onto the List. If you want to put them back into the matrix in sorted order, then you'll have to decide how to do that.

hunter9000a at 2007-7-7 15:42:10 > top of Java-index,Java Essentials,Java Programming...
# 5
You can leave your Strings in the matrix. Just when you need to sort them copy them over to a Collection and sort or use a TreeSet (which sorts as you add) and then copy all values back to your matrix.
floundera at 2007-7-7 15:42:10 > top of Java-index,Java Essentials,Java Programming...
# 6
So you are disallowed using ArrayList or any additional Class, not yet used? In that case, it will be difficult to sort easily or efficiently.
stefan.schulza at 2007-7-7 15:42:10 > top of Java-index,Java Essentials,Java Programming...
# 7

> So you are disallowed using ArrayList or any

> additional Class, not yet used? In that case, it will

> be difficult to sort easily or efficiently.

If it's part of your assignment that you can't use the classes we've suggested, and have to implement the sorting yourself, then the String class has a built in comparitor method you can use. Look up sorting algorithms and then apply the compareTo method to do the comparisons.

hunter9000a at 2007-7-7 15:42:10 > top of Java-index,Java Essentials,Java Programming...