Reversing the words order of a string A couple of weeks I had a coding interview and the problem to solve was very simple: reverse the words order of a string. What did I do wrong here?

public static String reverse(String phrase) {
        String[] words = phrase.split(" ");
        StringBuffer sb = new StringBuffer();
        for (String word : words) {
            String reversed = new String();
            for (int j = word.length() - 1; j &gt;= 0; j--) {
                reversed += word.charAt(j);
            }
            sb = sb.append(reversed).append(" ");
        }

        return sb.toString().substring(0, sb.toString().length() - 1);
    }
Thanks for your fast response guys, after reading your messages I tried to solve it different:

public static void reverse(String phrase, char delimiter) {
        char[] newPhrase = new char[phrase.length()];
        int start = 0, i = 0, currentPos = newPhrase.length;
        while (i &lt; phrase.length()) {
            if (phrase.charAt(i) == delimiter || i == phrase.length() - 1) {
                char[] word = phrase.substring(start, i).toCharArray();
                currentPos = currentPos - word.length;
                System.arraycopy(word, 0, newPhrase, currentPos, word.length);
                if (i != phrase.length() - 1) {
                    newPhrase[--currentPos] = delimiter;
                }
                start = ++i;
            } else {
                i++;
            }
        }

        System.out.println(new String(newPhrase));
    }