File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed
src/main/java/com/thealgorithms/strings Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -15,23 +15,27 @@ public static void main(String[] args) {
1515 }
1616
1717 /**
18- * Converts all the characters in this {@code String} to upper case
18+ * Converts all the characters in this {@code String} to upper case.
1919 *
2020 * @param s the string to convert
2121 * @return the {@code String}, converted to uppercase.
2222 */
2323 public static String toUpperCase (String s ) {
2424 if (s == null ) {
25- throw new IllegalArgumentException ("Input string connot be null" );
25+ throw new IllegalArgumentException ("Input string cannot be null" );
2626 }
2727 if (s .isEmpty ()) {
2828 return s ;
2929 }
30- StringBuilder result = new StringBuilder (s );
31- for (int i = 0 ; i < result .length (); ++i ) {
32- char currentChar = result .charAt (i );
33- if (Character .isLetter (currentChar ) && Character .isLowerCase (currentChar )) {
34- result .setCharAt (i , Character .toUpperCase (currentChar ));
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 );
3539 }
3640 }
3741 return result .toString ();
You can’t perform that action at this time.
0 commit comments