Parameters of toLowerCase()
- None: The toLowerCase() method does not take any parameters
Return Value of toLowerCase()
- String: The method returns a new string with all uppercase characters converted to lowercase. The original string remains unchanged.
Types of toLowerCase()
The string toLowerCase() method has two variants. The string toLowerCase() method's signature or syntax is as follows:
- String toLowerCase(): Converts all the characters into lowercase
- String toLowerCase(Locale locale): Using the rules of the given locale, convert all characters to lowercase.
String toLowerCase()
All the characters in a string are changed to lower case letters using the toLowerCase() function.
Signature of toLowercase()
Syntax:
public String toLowerCase()
- Access modifier: It is a public method.
- Parameters: method does not take any parameters.
- Returned value: It returns the lower case String value of a String object.
Implementation in Java
Java
class Main {
public static void main(String[] args) {
String string = "Welcome to CodingNinjas";
// convert letters to lowercaselower case
System.out.println(string.toLowerCase());
}
}

You can also try this code with Online Java Compiler
Run Code
Output
welcome to codingninjas
String toLowerCase(Locale locale)
All characters are converted to lowercase using the rules of the given locale. This method also allows us to pass the locale for the various languages. Let's look at an example where we get a string in both English and Turkish.
Signature of toLowercase(Locale locale)
Syntax:
public String toLowerCase(Locale loc)
If the locale parameter is missing, then locale.getDefault(), the default locale, is used.
Implementation in Java
Java
import java.util.Locale;
class StringLowerExample {
public static void main(String[] args) {
String s = "I WELCOME YOU TO CoDiNgNINJAS";
//string to English
String eng = s.toLowerCase(Locale.ENGLISH);
System.out.println(eng);
// It shows i without the upper dot
String turkish = s.toLowerCase(Locale.forLanguageTag("tr"));
System.out.println(turkish);
}
}

You can also try this code with Online Java Compiler
Run Code
Output
i welcome you to codingninjas
ı welcome you to codingnınjas
Example of Java toLowerCase()
Example 1: Basic Usage of toLowerCase()
Java
public class ToLowerCaseExample {
public static void main(String[] args) {
String originalString = "HELLO, WORLD!";
String lowerCaseString = originalString.toLowerCase();
System.out.println("Original String: " + originalString);
System.out.println("Lowercase String: " + lowerCaseString);
}
}

You can also try this code with Online Java Compiler
Run Code
Output:
Original String: HELLO, WORLD!
Lowercase String: hello, world!
Example 2: Using toLowerCase() with User Input
Java
import java.util.Scanner;
public class ToLowerCaseWithInput {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a string: ");
String userInput = scanner.nextLine();
String lowerCaseInput = userInput.toLowerCase();
System.out.println("Original String: " + userInput);
System.out.println("Lowercase String: " + lowerCaseInput);
scanner.close();
}
}

You can also try this code with Online Java Compiler
Run Code
Output:
Enter a string: Java Programming
Original String: Java Programming
Lowercase String: java programming
Frequently Asked Questions
Does toLowerCase change the original string?
Lowercase characters are added to a string using the toLowerCase() function. The original string is unchanged by the toLowerCase() method.
Is the toLowerCase() method locale-sensitive?
Yes, the toLowerCase() method can be locale-sensitive, as it can behave differently based on the default locale of the JVM. To ensure consistent results across locales, you can use toLowerCase(Locale locale) for specific locale handling.
How does the toLowerCase() method handle non-alphabetic characters?
The toLowerCase() method leaves non-alphabetic characters unchanged. It only converts uppercase alphabetic characters to lowercase, so numbers, punctuation, and other symbols remain unaffected in the resulting string.
Can toLowerCase() be used on an empty string?
Yes, the toLowerCase() method can be used on an empty string. It will return an empty string as well, since there are no characters to convert, ensuring no errors occur in the process.
Conclusion
In this article, we discussed the String toLowerCase() method in Java. The toLowerCase() method in Java is a powerful and essential tool for string manipulation. By converting uppercase characters to lowercase, this method facilitates uniformity in text processing, making it particularly useful for tasks such as case-insensitive comparisons and data normalization. Its simple syntax and ability to handle various string inputs, including empty strings and those with non-alphabetic characters, make it highly versatile.
Check out our articles on
Recommended problems -