// // String Reverse By Words // public class reverseByWords { public static String toString(String source) { String revSource = reverseByLetters.toString(source); // Walk through the reversed list, finding blank-separated // tokens and appending them to a destination string with // re-reversals of the individual words. char whiteSpace = ' '; int startLoc = 0; int wsLoc = 1; String word, newString = ""; while (wsLoc >= 0) { wsLoc = revSource.indexOf(whiteSpace, startLoc); if (wsLoc < 0) { word = revSource.substring(startLoc); if (word.length() > 0) newString += reverseByLetters.toString(word); break; } word = revSource.substring(startLoc, wsLoc); if (word.length() > 0) newString += reverseByLetters.toString(word) + " "; startLoc = wsLoc+1; } return newString; } }