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
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.