Java Case Conversion: Uppercase & Lowercase Methods

There are several methods for converting case in Java.

  1. Convert the string to uppercase using the toUpperCase() method.
String str = "HelloWorld";
String upperCaseStr = str.toUpperCase();
System.out.println(upperCaseStr); // 输出:HELLOWORLD
  1. Convert the string to lowercase using the toLowerCase() method.
String str = "HelloWorld";
String lowerCaseStr = str.toLowerCase();
System.out.println(lowerCaseStr); // 输出:helloworld
  1. Convert characters to uppercase using the toUpperCase() method of the Character class.
char c = 'a';
char upperCaseChar = Character.toUpperCase(c);
System.out.println(upperCaseChar); // 输出:A
  1. Convert characters to lowercase using the toLowerCase() method of the Character class.
char c = 'A';
char lowerCaseChar = Character.toLowerCase(c);
System.out.println(lowerCaseChar); // 输出:a
bannerAds