Java String toLowerCase() Method



The Java String toLowerCase() method is used to convert all the characters of the given string into lowercase letters.

This method has two polymorphic variants; one without any arguments and, the other uses the criteria outlined by the given Locale data type to convert the string into lowercase. The syntaxes of these methods are given below.

Note: Keep in mind that case mapping is based on the Unicode Standard Version of Character class standard. Since the case mappings are not necessarily 1:1, the length of the new string that is produced may or may not match that of the original String.

Syntax

Following is the syntax for Java String toLowerCase() method −

public String toLowerCase() 
or,
public String toLowerCase(Locale locale)

Parameters

  • locale − use the case transformation rules for this locale. // second syntax

Return Value

This method returns the String, converted to lowercase.

Example

The following example shows the usage of Java String toLowerCase() method by converting the given characters of the string into its lower case letters without passing any arguments −

import java.lang.*; 
public class StringDemo {
   public static void main(String[] args) {
      
      // converts all upper case letters in to lower case letters
      String str1 = "Self Learning Center";
      System.out.println("string value = " + str1.toLowerCase());    
      str1 = "www.photofuntoos.com";
      System.out.println("string value = " + str1.toLowerCase());
   } 
}

Output

If you compile and run the above program, it will produce the following result −

string value = self learning center
string value = www.photofuntoos.com

Example

Below is an example to convert the characters in a string to lower case by passing the Locale value to the toLowerCase() method −

import java.lang.*;
import java.util.*; 
public class StringDemo {
   public static void main(String[] args) {
      String str1 = "Self Learning Center";   
      
      // using the default system Locale
      Locale defloc = Locale.getDefault();        
      
      // converts all upper case letters in to lower case letters
      System.out.println("string value = " + str1.toLowerCase(defloc));    
      str1 = "WWW.PHOTOFUNTOOS.COM";
      System.out.println("string value = " + str1.toLowerCase(defloc));
   }
}

Output

If you compile and run the program above, the output will be displayed as follows −

string value = self learning center
string value = www.photofuntoos.com

Example

Let's create another code that will generate a string of characters that includes letters, numerals, and symbols. In this program, we will determine whether or not the toLowerCase() method affects non-alphabetical characters like numbers and symbols −

public class StringDemo {
   public static void main(String[] args) {
      String s = "Welcome to @!! Tutorials point 77!!";
      System.out.println("The given string  is: " + s);
      String toLower = s.toLowerCase();
      System.out.println("String after conversion is: " + toLower);
   }
}

Output

On executing the program above, the output is obtained as follows −

The given string  is: Welcome to @!! Tutorials point 77!!
String after conversion is: welcome to @!! tutorials point 77!!

Example

In the example given below we are creating a program that converts the string “Welcome to turialspoint” into lowercase English letters by passing locale argument −

import java.util.Locale; 
public class StringDemo {
   public static void main(String[] args) {
      String s = new String("Welcome to turialspoint");
      System.out.println("The given string is: " + s);
      
      // Create Locale "Eng" for english.
      Locale English = Locale.forLanguageTag("Eng");
      System.out.println("Lowercase letters in english: " + s.toLowerCase(English));
   }
}

Output

The output of the above program is as follows −

The given string is: Welcome to turialspoint
Lowercase letters in spanish: welcome to turialspoint
Lowercase letters in english: welcome to turialspoint
java_lang_string.htm
Advertisements