Skip to content

Instantly share code, notes, and snippets.

@kahrl kahrl/gist:985726
Created May 22, 2011

Embed
What would you like to do?
public static String initCap(String s) {
StringBuffer result = new StringBuffer(s.length());
boolean upper = true;
for (int i = 0; i < s.length(); ++i) {
char c = s.charAt(i);
if (Character.isWhitespace(c)) {
upper = true;
} else if (upper) {
c = Character.toUpperCase(c);
upper = false;
} else {
c = Character.toLowerCase(c);
}
result.append(c);
}
return result.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.