Last active
December 13, 2015 19:58
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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