Skip to content

Sort a string using Stream API in Java 8

Java does not have a direct method to sort a string. You can do it using Stream API provided in Java 8.

public static String sortString(String str) {
    return Arrays.stream(str.split("")).sorted().collect(Collectors.joining());
}


//sortString("poopcode")

//cdeooopp
See also  How to increment date by one day in Java?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.