character arrays

I need help with a character arrays.i have a string of alphanumeric characters (i.e. gF44dbE)which i need to sort into alphabetical order (i.e 44EFbdg)i want to do to this using a character array, can anyone help?
[241 byte] By [ca4mjea] at [2007-11-26 14:43:15]
# 1
Sure. What kind of help do you need in writing those three lines of code?1. Convert the string to an array of chars.2. Sort it.3. Convert it back to a string.
DrClapa at 2007-7-8 8:30:53 > top of Java-index,Java Essentials,Java Programming...
# 2
String has a method to make a character array. Arrays has a method to sort arrays.
es5f2000a at 2007-7-8 8:30:53 > top of Java-index,Java Essentials,Java Programming...
# 3
I dont kno how to convert it into an array of chars, or how to sort it, or how to convert it back to a string, lol
ca4mjea at 2007-7-8 8:30:53 > top of Java-index,Java Essentials,Java Programming...
# 4
> I dont kno how to convert it into an array of chars,> or how to sort it, or how to convert it back to a> string, lolTackle one step at a time.Ask specific questions when you are stuck.
DrLaszloJamfa at 2007-7-8 8:30:53 > top of Java-index,Java Essentials,Java Programming...
# 5

Here are a few links that should help you out:

[url=http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#toCharArray()]java.lang.String.toCharArray()[/url]

[url=http://java.sun.com/j2se/1.5.0/docs/api/java/util/Arrays.html#sort(char[])]java.util.Arrays.sort(char[])[/url]

[url=http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#valueOf(char[])]java.lang.String.valueOf(char[])[/url]

These should cover the three operations you need.

... learn to use the docs. They are invaluable to a java programmer.

- Adam

guitar_man_Fa at 2007-7-8 8:30:53 > top of Java-index,Java Essentials,Java Programming...
# 6
ok, ive worked out how to make the char array, which is the best way to sort the characters in it alphanumerically (as noted above)?Message was edited by: ca4mje
ca4mjea at 2007-7-8 8:30:54 > top of Java-index,Java Essentials,Java Programming...
# 7

> ok, ive worked out how to make the char array,

>

> which is the best way to sort the characters in it

> alphanumerically (as noted above)?

>

> Message was edited by:

> ca4mje

try using the resources list above.

if your planning on implementing the sorting procedure yourself, then asking about the best way to do it is opening a real can of worms on this forum. There are hundreds of different sorting algorithms that different programmers will swear by.

If your a beginner, I would suggest a bubble sort. It's probably the best documented algorithm out there, and it's pretty straight forward to understand how it works. However, it is slightly slow, especially if your list is large.

- Adam

guitar_man_Fa at 2007-7-8 8:30:54 > top of Java-index,Java Essentials,Java Programming...
# 8
The best way is to call the Arrays.sort() method.
DrClapa at 2007-7-8 8:30:54 > top of Java-index,Java Essentials,Java Programming...
# 9
Thats cool thanks, that worked a treat
ca4mjea at 2007-7-8 8:30:54 > top of Java-index,Java Essentials,Java Programming...