Skip to content

Commit

Permalink
Add StringUtil.capitalize() method
Browse files Browse the repository at this point in the history
  • Loading branch information
CarpenterLee committed Oct 19, 2018
1 parent 1f3640f commit bbea62a
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,22 @@ private static boolean regionMatches(final CharSequence cs, final boolean ignore

return true;
}

public static String capitalize(String str) {
return changeFirstCharacterCase(str, true);
}

private static String changeFirstCharacterCase(String str, boolean capitalize) {
if (str == null || str.length() == 0) {
return str;
}
StringBuilder buf = new StringBuilder(str.length());
if (capitalize) {
buf.append(Character.toUpperCase(str.charAt(0)));
} else {
buf.append(Character.toLowerCase(str.charAt(0)));
}
buf.append(str.substring(1));
return buf.toString();
}
}

0 comments on commit bbea62a

Please sign in to comment.