Java String to LowerCase With Examples

Java String to lowercase conversion can be done using toLowerCase() method.

Java String to LowerCase

  • Java String toLowerCase() method has two variants – toLowerCase() and toLowerCase(Locale locale).
  • Conversion of the characters to lower case is done by using the rules of default locale. Calling toLowerCase() function is same as calling toLowerCase(Locale.getDefault()).
  • Java String to lower case method is locale sensitive, so use it carefully with strings that are intended to be used locale independently. For example programming language identifiers, HTML tags, protocol keys etc. Otherwise you might get unwanted results.
  • To get correct lower case results for locale insensitive strings, use toLowerCase(Locale.ROOT) method.
  • String toLowerCase() returns a new string, so you will have to assign that to another string. The original string remains unchanged because Strings are immutable.
  • If locale is passed as null to toLowerCase(Locale locale) method, then it will throw NullPointerException.

Java String to LowerCase Example

Let’s see a simple example to convert a string to lower case and print it.

We can also use Scanner class to get user input and then convert it to lower case and print it.

Here is a complete example program to convert java string to lowercase and print it.

Below image shows the output from a sample execution of above program.


That’s all for java string to lowercase conversion example.

Reference: API Doc

By admin

Leave a Reply

%d bloggers like this: