Java 25 (LTS) reference · String Methods
Java String toUpperCase() Method
Return a copy of the string in upper case. toLowerCase() does the opposite.
Java 25 (LTS) Since Java 1.0
Syntax
string.toUpperCase()
Return value
A new String.
Examples
public class Main {
public static void main(String[] args) {
String s = "Hello Java";
System.out.println(s.toUpperCase());
System.out.println(s.toLowerCase());
System.out.println(s); // unchanged: strings are immutable
}
}
Output
HELLO JAVA hello java Hello Java
Run this on your computer — see “Get Started” for setup.
public class Main {
public static void main(String[] args) {
String input = "YES";
boolean agreed = input.toLowerCase().equals("yes");
System.out.println(agreed);
}
}
Output
true
Run this on your computer — see “Get Started” for setup.
Version history
| Version | Change |
|---|---|
| Java Java 1.0 | Added |
Related
string.equals()· Compare the contents of two strings. Never use == for strings: it compares object identity, not text.- Java Strings · tutorial