Skip to content

Convert String to uppercase or lowercase in Java Example

This Java example shows how to convert String to uppercase or lowercase using toUpperCase() and toLowerCase() methods of the String class as well as by using Apache Commons.

How to check if the String is in uppercase?

How to check if the String is in lowercase?

How to convert String to uppercase?

To convert string to the upper case, use the toUpperCase() method of the Java String class.

This method converts all the characters of a string to upper case using the default locale. Internally it is same as calling the toUpperCase(Locale.getDefault()) method.

Output

Using the Apache Commons Library

If you are using the Apache Commons library in your project, you can use the upperCase method of the StringUtils class to change case of a string to upper case.

How to convert String to lowercase?

To convert string to lower case, use the toLowerCase() method of the String class.

This method converts all the characters of a string to lower case using the default locale. Internally it is same as calling the toLowerCase(Locale.getDefault()) method.

Output

Using the Apache Commons Library

If you are using the Apache Commons library in your project, you can use the lowerCase method of the StringUtils class to change case of a string to lower case.

Important Note:

Both the toUpperCase() and toLowerCase() methods are locale sensitive. It could produce unexpected results if used on the strings which are intended to be interpreted locale independently.

If you are working with the string values which are locale insensitive, you should use the toUpperCase(Locale locale) or toLowerCase(Locale locale) methods instead.

This example is a part of the Java String tutorial.

Please let me know your views in the comments section below.

About the author

Leave a Reply

Your email address will not be published.