• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic