/**
* @author lautturi.com
* Java example: how to sort the characters in a string
*/
import java.util.*;
import java.util.stream.Collectors;
public class Lautturi {
public static void main(String[] args) {
String str = "hello lautturi java world!";
char[] chars = str.toCharArray();
Arrays.sort(chars);
String sorted = new String(chars);
System.out.println("original:"+str);
System.out.println("sorted String:"+sorted);
}
}
output:
original:hello lautturi java world! sorted String: !aaadehijlllloorrttuuvw