toLowerCase() Method in Java

Rumman Ansari   Software Engineer   2019-03-30   6490 Share
☰ Table of Contents

Table of Content:


Description

The Character.toLowerCase(char ch) java method converts the character argument to lowercase using case mapping information from the UnicodeData file.

 

Note that Character.isLowerCase(Character.toLowerCase(ch)) does not always return true for some ranges of characters, particularly those that are symbols or ideographs.

In general, String.toLowerCase() should be used to map characters to lowercase. String case mapping methods have several benefits over Character case mapping methods. String case mapping methods can perform locale-sensitive mappings, context-sensitive mappings, and 1:M character mappings, whereas the Character case mapping methods cannot.

This method cannot handle supplementary characters. To support all Unicode characters, including supplementary characters, use the toLowerCase(int) method.

toLowerCase(char ch) returns the lowercase form of the specified char value.

Method Syntax

public static char toLowerCase(char ch)

Method Argument

Data Type Parameter Description
char ch the character to be converted. Primitive character type.

Method Returns

The toLowerCase(char ch) method of Character class returns the lowercase equivalent of the character, if any; otherwise, the character itself or we can say this method returns the lowercase form of the specified char value.

Compatibility

Requires Java 1.5 and up

Example

Below is a simple java example on the usage of toLowerCase(char ch) method of Character class.

public class MethodtoLowerCase {

   public static void main(String args[]) {
      System.out.println(Character.toLowerCase('s'));
      System.out.println(Character.toLowerCase('S'));
   }
}

output

Below is the sample output when you run the above example.

s
s
Press any key to continue . . .

Example

Below is a simple java example on the usage of toLowerCase(char ch) method of Character class.



import java.util.Scanner;

/*
 * This example source code demonstrates the use of
 * toLowerCase(char ch) method of Character class.
 */

public class CharacterToLowerCaseChar {

	public static void main(String[] args) {

		// Ask for user input
		System.out.print("Enter an input:");

		// use scanner to get the user input
		Scanner s = new Scanner(System.in);

		// get a single character
		char[] value = s.nextLine().toCharArray();

		// close the scanner object
		s.close();

		// convert user input to lower case
		for(char ch:value){
			char chLower = Character.toLowerCase(ch);
			// print the result
			System.out.println("character "+ch +" lower case is " +chLower);
		}

	}

}

output

Below is the sample output when you run the above example.

Enter an input:S
character S lower case is s
Press any key to continue . . .


Enter an input:R
character R lower case is r
Press any key to continue . . .

The toLowerCase(char ch) method of Character class is static thus it should be accessed statically which means the we would be calling this method in this format:

Character.toLowerCase(char ch)

Non static method is usually called by just declaring method_name(argument) however in this case since the method is static, it should be called by appending the class name as suffix. We will be encountering a compilation problem if we call the java toLowerCase() method non statically.