MCPcopy Create free account
hub / github.com/TheAlgorithms/Java / toUpperCase

Method toUpperCase

src/main/java/com/thealgorithms/strings/Upper.java:23–42  ·  view source on GitHub ↗

Converts all the characters in this String to upper case. @param s the string to convert @return the String, converted to uppercase.

(String s)

Source from the content-addressed store, hash-verified

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}

Callers 15

toUpperCaseMethod · 0.95
mainMethod · 0.95
toTitleCaseMethod · 0.45
crc16Method · 0.45
abbrMethod · 0.45
getHexaToDecMethod · 0.45
textToMorseMethod · 0.45
hexToDecimalMethod · 0.45
textToPhoneticMethod · 0.45
romanToIntMethod · 0.45
encodeMethod · 0.45
decodeMethod · 0.45

Calls 4

lengthMethod · 0.80
isEmptyMethod · 0.65
appendMethod · 0.45
toStringMethod · 0.45

Tested by 1

toUpperCaseMethod · 0.76