Skip to content

Latest commit

 

History

History
23 lines (19 loc) · 649 Bytes

reverse-word-contents.md

File metadata and controls

23 lines (19 loc) · 649 Bytes
Title Description Author Tags
Reverse Word Contents
Reverses the characters of each word in a string while preserving word order
Mcbencrafter
string,reverse,words,transformation,order
public static String reverseWords(String text) {
    String[] words = text.split("\\s+"); 
    StringBuilder reversedText = new StringBuilder();

    for (String word : words) {
        StringBuilder reversedWord = new StringBuilder(word).reverse();
        reversedText.append(reversedWord).append(" ");
    }

    return reversedText.toString().trim();
}

// Usage:
System.out.println(reverseWordContents("hello world")); // "olleh dlrow"