Forums Register Login

How to sort String, for example: abced. to change to abcde

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
Have you no shame? Have you no decency? Have you no tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1383 times.
Similar Threads
References in JAVA
is there a sizeof() in Java?
Refering variables of class which extends applet
Passed SCJP 1.2
Java String pool problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 20:34:47.