In this section, we will learn what the String toLowerCase() method is and how to use it in Java.
What is Java String toLowerCase() Method?
The `toLowerCase()` method is used to turn all the letters of a string value into lowercase and return them as a new string object.
Note: the method does not change the content of the original string value because after all string objects are immutable. It will basically take a copy of the string, convert into lowercase letters and return the result.
Java toLowerCase() Method Syntax:
public String toLowerCase()
toLowerCase() Method Parameters:
This method does not take an argument.
toLowerCase() Method Return Value:
The return value of this method is a new string with the content of the target string but all the letters is converted into lowercase.
toLowerCase() Method Exceptions:
This method does not throw an exception.
Example: convert string to lowercase using String toLowerCase() method
public class Simple { public static void main(String[] args) { String s1 = "BE KIND TO ONE ANOTHER"; String res = s1.toLowerCase(); System.out.println(res); } }
Output:
be kind to one another