Java provides .toUpperCase() and .toLowerCase() to convert every letter in a string to uppercase or lowercase. Non-letter characters like digits and punctuation stay unchanged.
String original = "Hello World 123";
System.out.println(original.toUpperCase());
System.out.println(original.toLowerCase());
This prints HELLO WORLD 123 and then hello world 123. Remember, strings are immutable. Neither method modifies original. Both return a new String object.
A common use case is case-insensitive comparison. Instead of writing a custom check, convert both strings to the same case first:
String input = "Yes";
if (input.toLowerCase().equals("yes")) {
System.out.println("Confirmed");
}
You can also use .equalsIgnoreCase(), which does the same thing in a single call.