Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String capitalize(final String str) {
- int strLen;
- if (str == null || (strLen = str.length()) == 0) {
- return str;
- }
- final char firstChar = str.charAt(0);
- if (Character.isTitleCase(firstChar)) {
- // already capitalized
- return str;
- }
- return new StringBuilder(strLen)
- .append(Character.toTitleCase(firstChar))
- .append(str.substring(1))
- .toString();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement