need help with alphabetizing

hi, i'm looking for a piece of code that will help me alphabetize an inputted string, such as: "Hello, how are you." would be updated as

"aehhllooorwy", with the alphabets in order. the program i use is Java IDE i think its version 5.

P.S: i'm in grade 11, so not too complicated codes

thank you

[323 byte] By [monkeyhella] at [2007-11-27 3:54:29]
# 1

Once you have a string, you can turn it into an array of char using String.toCharArray(), like this:

char[] mychars = "hello".toCharArray();

or

String myString = getTheStringHoweverYouLike();

char[] mychars = myString.toCharArray();

Then you can use java.util.Arrays.sort to sort the array.

Then you can use the String constructor that takes an array of char.

You'd then end up with a String that's a version of the original String, only all the chars are sorted.

paulcwa at 2007-7-12 8:58:37 > top of Java-index,Java Essentials,Java Programming...
# 2
If you do as Paul suggested you would also need to make a final call to trim() to remove spaces.
floundera at 2007-7-12 8:58:37 > top of Java-index,Java Essentials,Java Programming...