String.toUpperCase()
Returns a copy of the string with all letters in upper case.
Available since: Java 1.0
Syntax
public String toUpperCase()Return value
StringA new string in upper case.
Examples
Converting to upper case:
void main() {
String name = "anna";
IO.println(name.toUpperCase());
IO.println(name);
}Output:
ANNA
annaCapitalizing only the first letter:
void main() {
String word = "java";
String result = word.substring(0, 1).toUpperCase() + word.substring(1);
IO.println(result);
}Output:
JavaNotes
The method does not change the original string — store the result: name = name.toUpperCase();.
Without an argument it uses the system language rules. In the Turkish locale "i" becomes "İ", so for technical strings (keys, commands) write toUpperCase(Locale.ROOT).
See also
- String.toLowerCase() — Returns a copy of the string with all letters in lower case.
- String.equalsIgnoreCase() — Compares two strings ignoring letter case.
Related recipes
In the tutorial
- String methods — The main String methods in Java: searching, substring, changing case, strip, replace, split, join, repeat and string checks.