Alphabetically sorting characters in a string

Discussion in 'Java' started by Karsten Wutzke, Jan 6, 2004.

  1. Hi all!

    Is there an easy way of alphabetically sorting characters in a string? I
    have a string like "xzya" and I want it to become "axyz".

    Do I have to sort them manually?

    Karsten Wutzke, Jan 6, 2004
    1. Advertisements

  2. Something like

    String unsorted = "xzya";
    char[] content = unsorted.toCharArray();
    String sorted = new String(content);

    should do the trick.
    Christophe Vanfleteren, Jan 6, 2004
    1. Advertisements

  3. Thanks! I didn't know that one...

    Karsten Wutzke, Jan 6, 2004
  4. Karsten Wutzke

    Roedy Green Guest

    Roedy Green, Jan 7, 2004
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.