java.lang.String toLowerCase(Locale locale)

Description :

This java tutorial shows how to use the toLowerCase(Locale locale) method of String class of java.lang package. This method returns a new String object as a string representation in lower case of our String depending on the Locale specified as method argument . The toLowerCase() method is simply converts the string object into lower case.

Make a note that case mapping is based on the Unicode Standard Version of Character class specification. The case mappings is not always 1:1 thus the new string generated may or may not be of the same length as the original String.

Method Syntax :

public String toLowerCase(Locale locale)

Parameter Input :

DataType Parameter Description
Locale locale This parameter serves as a rule in changing the characters in lower case

Method Returns :

This String toLowerCase(Locale locale) method returns a new String object. The new string object is equal to String in lower case format based on the transformation rule specified by the Locale method argument.

Compatibility Version :

Requires Java 1.1 and up

Exception :

N/A

Discussion :

Since a String can never be changed once instantiated, thus a new string object variable is required to hold the new string. This method is helpful especially if we are comparing data which comes from different systems.

In my experience as a developer, usually the strings that comes from user inputs are on different format. Sometimes all caps, or all are small caps and sometimes the First letter is in big letter only. To normalize this kind of situation before storing the information, I usually convert first the information into lower case.

Java Code Example :

This example source code demonstrates the use of toLowerCase() of String class. The example provided just converts the String name into lower case using the English locale. We have used the Locale.English constant in determining the locale argument.

package com.javatutorialhq.java.tutorial.string;

import java.util.Locale;

/*
 * Example source code for toLowerCase(Locale) method of String class
 */

public class StringtoLowerCaseDemo {

	public static void main(String[] args) {
		// declaring our String object
		String name = "AlberT einstein";
		// declaring what locale to be used
		Locale locale = Locale.ENGLISH;
		// changing to lower case
		String lowerCaseName = name.toLowerCase(locale);
		System.out.println("Name in Lower Case: "+lowerCaseName);

	}

}

Sample Output :

Running the toLowerCase(Locale locale) method example source code of String class will give you the following output.

string toLowerCase(Locale) method example

string toLowerCase(Locale) method example

Exception Scenario :

N/A

Similar Method :

  • java.lang.String toLowerCase()

Suggested Reading List :