Java Data Type How to - Convert String case








Question

We would like to know how to convert String case.

Answer

To convert the content of a string to lower and upper case, use the toLowerCase() and the toUpperCase() methods, respectively.

String str1 = new String("Hello"); // str1  contains "Hello" 
String str2 = str1.toUpperCase();   // str2 contains "HELLO" 
String str3 = str1.toLowerCase();   // str3 contains "hello"