| Author |
How to sort String, for example: abced. to change to abcde
|
sandeeps srivastava
Greenhorn
Joined: Jul 25, 2008
Posts: 7
|
|
hi , i am beginners in java , i have proble to sorting a string for example how we sort abecd into abcde in java please help
|
 |
Amit Ghorpade
Bartender
Joined: Jun 06, 2007
Posts: 2551
|
|
Let us know how far have you gone with the problem. Hint:You can use the charAt() method and any sorting mechanism you wish to implement.
|
SCJP, SCWCD.
|Asking Good Questions|
|
 |
Piet Verdriet
Ranch Hand
Joined: Feb 25, 2006
Posts: 266
|
|
1 - create an array of characters from String X; 2 - sort the character array; 3 - create a new String from the sorted array; 4 - reassign X to the newly created String; 5 - have a beer... err... cup of coffee! Have a look at the String- and Arrays API docs for steps 1, 2 and 3: http://java.sun.com/j2se/1.5.0/docs/api/java/util/Arrays.html http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9946
|
|
Is this a homework assignment? What have you tried? are you allowed to use all the tools in the api, or do you have to write your own sort? I'd strongly recommend you read our FAQ to get the most out of the JavaRanch.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
 |
|
|
subject: How to sort String, for example: abced. to change to abcde
|
|
|