Verifying Lowercase Characters with isLowerCase() Method in Java: A Comprehensive Guide

Rumman Ansari   Software Engineer   2024-07-04 04:33:11   7063  Share
Subject Syllabus DetailsSubject Details
☰ TContent
☰Fullscreen

Table of Content:

Description

The Character.isLowerCase(char ch) java method determines if the specified character is a lowercase character.

 

A character is lowercase if its general category type, provided by Character.getType(ch), is LOWERCASE_LETTER, or it has contributory property Other_Lowercase as defined by the Unicode Standard.

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

The isLowerCase(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.isLowerCase(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 isLowerCase() method non statically.

The method determines whether the specified char value is lowercase.

Method Syntax

public static boolean isLowerCase(char ch)

Method Argument

Data Type Parameter Description
char ch the character to be tested.

Method Returns

The isLowerCase(char ch) method of Character class returns true if the character is lowercase; false otherwise. or we can say this method returns true, if the passed character is really in lowercase.

Compatibility

Java Character isLowerCase(char ch) Example

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

public class MethodIsLowerCase {

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

output

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

true
false
false
false
Press any key to continue . . .

Another Example

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

 
import java.util.Scanner;

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

public class CharacterIsLowerCaseChar {

	public static void main(String[] args) {


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

		// use scanner to get the user input
		Scanner s = new Scanner(System.in);
		// get a single character
		char value = s.nextLine().toCharArray()[0];

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

		// check if the user input is lower case or not
		boolean checkBool = Character.isLowerCase(value);
		// print result
		if(checkBool){
			System.out.println("User input \'"+value+"\' is lower case");
		}
		else{
			System.out.println("User input \'"+value+"\' is not lower case");
		}

	}

}

output

This will produce the following result ?

Enter a character:s
User input 's' is lower case
Press any key to continue . . .


Enter a character:S
User input 'S' is not lower case
Press any key to continue . . .