Capitalizes a String, changing the first letter to upper case as per Character#toUpperCase(char). No other letters are changed. @param str the String to capitalize @return the capitalized String
(String str)
| 38 | * @return the capitalized {@link String} |
| 39 | */ |
| 40 | public static String capitalize(String str) { |
| 41 | if (str == null || str.isEmpty()) { |
| 42 | return str; |
| 43 | } |
| 44 | char oldFirst = str.charAt(0); |
| 45 | char newFirst = Character.toUpperCase(oldFirst); |
| 46 | if (oldFirst == newFirst) { |
| 47 | return str; |
| 48 | } |
| 49 | char[] chars = str.toCharArray(); |
| 50 | chars[0] = newFirst; |
| 51 | return new String(chars); |
| 52 | } |
| 53 | |
| 54 | } |
no test coverage detected