Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

change order of words in string java

public static String reverseName (String name) {

    name = name.trim();

    StringBuilder reversedNameBuilder = new StringBuilder();
    StringBuilder subNameBuilder = new StringBuilder();

    for (int i = 0; i < name.length(); i++) {

        char currentChar = name.charAt(i);

        if (currentChar != ' ' && currentChar != '-') {
            subNameBuilder.append(currentChar);
        } else {
            reversedNameBuilder.insert(0, currentChar + subNameBuilder.toString());
            subNameBuilder.setLength(0);
        }

    }

    return reversedNameBuilder.insert(0, subNameBuilder.toString()).toString();

}
Comment

PREVIOUS NEXT
Code Example
Java :: java lambda expression in priorityqueue 
Java :: open youtube by default in full landscape mode pragmatically 
Java :: como limitar o random em java 
Java :: Jax-RS path annotation 
Java :: Java @SuppressWarnings Annotation Example 
Java :: java stream anymatch vs findany 
Java :: java preprocessor example 
Java :: extended window style values in java 
Java :: for-each Loop Sytnax JAVA 
Java :: Switch statement expressions jdk12+ 
Java :: ex javaloop 
Java :: copy array of objects in java 
Java :: x squared unicode java code 
Java :: android java shared preferences 
Java :: java blocks 
Java :: selenium code for login 
Java :: pojo api testing 
Java :: react-native maven package 404 not found 
Java :: sending file over socket stream 
Java :: android studio viewpager 
Java :: write a code to print second last word of input string 
Java :: mostrar divisores java 
Java :: exception(string message throwable cause) 
Java :: remove minimum element from stack java 
Java :: java print color in console eclipse 
Java :: Java Default capacity and load factor 
Java :: java opengl get fps 
Java :: how to print multi dimension array in java using for each loop 
Java :: OkHttp3 Never Timeout on slow internet 
Java :: how to print an array in TImber android 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =