Table of contents
1.
Introduction
2.
Syntax of toLowerCase()
3.
Parameters of toLowerCase()
4.
Return Value of toLowerCase()
5.
Types of toLowerCase()
5.1.
String toLowerCase()
5.1.1.
Signature of toLowercase()
5.1.2.
Implementation in Java
5.2.
Java
5.3.
String toLowerCase(Locale locale)
5.3.1.
Signature of toLowercase(Locale locale)
5.3.2.
Implementation in Java
5.4.
Java
6.
Example of Java toLowerCase()
6.1.
Example 1: Basic Usage of toLowerCase()
6.2.
Java
6.3.
Example 2: Using toLowerCase() with User Input
6.4.
Java
7.
Frequently Asked Questions
7.1.
Does toLowerCase change the original string?
7.2.
Is the toLowerCase() method locale-sensitive?
7.3.
How does the toLowerCase() method handle non-alphabetic characters?
7.4.
Can toLowerCase() be used on an empty string?
8.
Conclusion
Last Updated: Jan 8, 2025
Medium

Java String toLowerCase() method

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

The Java language has substantial advantages over other programming languages and environments, making it ideal for almost any programming task. Java has the following advantages: Java is simple to learn. Java was created to be easy to use, making it easier to write, build, debug, and learn than other programming languages.

The Java String toLowerCase() function is used to convert all letters in a string to lowercase.The string toLowerCase() method is similar to the toLowerCase(Locale.getDefault()) method.

The toUpperCase() method converts the string to upper case letters.
 

String to LowerCase

Syntax of toLowerCase()

String lowerCaseString = originalString.toLowerCase();

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

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

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

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

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 -

Live masterclass