Converts all the characters in this String to upper case. @param s the string to convert @return the String, converted to uppercase.
(String s)
| 21 | * @return the {@code String}, converted to uppercase. |
| 22 | */ |
| 23 | public static String toUpperCase(String s) { |
| 24 | if (s == null) { |
| 25 | throw new IllegalArgumentException("Input string cannot be null"); |
| 26 | } |
| 27 | if (s.isEmpty()) { |
| 28 | return s; |
| 29 | } |
| 30 | |
| 31 | StringBuilder result = new StringBuilder(s.length()); |
| 32 | |
| 33 | for (int i = 0; i < s.length(); ++i) { |
| 34 | char currentChar = s.charAt(i); |
| 35 | if (Character.isLowerCase(currentChar)) { |
| 36 | result.append(Character.toUpperCase(currentChar)); |
| 37 | } else { |
| 38 | result.append(currentChar); |
| 39 | } |
| 40 | } |
| 41 | return result.toString(); |
| 42 | } |
| 43 | } |