Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Types of toLowerCase()
3.
String toLowerCase()
3.1.
Signature of toLowercase()
3.2.
Implementation in Java
4.
String toLowerCase(Locale locale)
4.1.
Signature of toLowercase(Locale locale)
4.2.
Implementation in Java
5.
Frequently Asked Questions
5.1.
Does toLowerCase change the original string?
5.2.
How do I convert a character to lowercase?
5.3.
What is the Java locale?
6.
Conclusion
Last Updated: Mar 27, 2024
Medium

Java String toLowerCase() method

Leveraging ChatGPT - GenAI as a Microsoft Data Expert
Speaker
Prerita Agarwal
Data Specialist @
23 Jul, 2024 @ 01:30 PM

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

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.
Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

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

class Main {
  public static void main(String[] args) {
    String string = "Welcome to CodingNinjas";

    // convert letters to lowercaselower case
    System.out.println(string.toLowerCase());

  }
}


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

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);
    }  
}


Output

i welcome you to codingninjas
ı welcome you to codingnınjas

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.
 

How do I convert a character to lowercase?

Using case mapping data from the UnicodeData file, toLowerCase(char ch) lowercases the character argument.
 

What is the Java locale?

A locale object represents a particular geographical, political, or cultural region. Locale-sensitive operations employ the locale to customize information for the user and are operations that need a Locale to complete their task.

Conclusion

In this article, we discussed how to convert all the letters to lowercase using the String toLowerCase() method in Java. We also illustrated toLowerCase() method with different locale.

If this blog has helped you enhance your knowledge about the above Java method. Check out our articles on Understanding StringsStrings OperationsInterview questions on Strings, and many more in our Library.
 

Recommended problems -

Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive ProgrammingJavaScriptSystem Design, String Interview Questions In Java and many more! You can check out the mock exam series and take part in the contests held on Coding Ninjas Studio to test your coding proficiency. But if you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc. In that case, you must look at the problemsinterview experiences, and interview bundle for placement preparations.

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!

Live masterclass