Skip to content

Instantly share code, notes, and snippets.

@vikalpsingh
Last active December 13, 2015 19:58
public reverse(String word) {
char[] chs = word.toCharArray();
int i=0, j=chs.length-1;
while (i < j) {
// swap chs[i] and chs[j]
char t = chs[i];
chs[i] = chs[j];
chs[j] = t;
i++; j--;
}
}
//Another way using java utility.
import org.apache.commons.lang.StringUtils;
String reverseWords(String sentence) {
return StringUtils.reverseDelimited(StringUtils.reverse(sentence), ' ');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment