Java - Character isLowerCase() Method



The Java Character isLowerCase() method determines if a character is a lowercase character or not.

A character is lowercase if its general category type is LOWERCASE_LETTER, as obtained from the return value of the Character.getType() method; or it has contributory property Other_Lowercase as defined by the Unicode Standard.

Lowercase, in general, is defined as a writing style that contains all the characters with their capitalization removed. Therefore, this style is usually void of capital letters.

However, there are some characters in Unicode system that are neither lowercased or uppercased.

Syntax

Following is the syntax for Java Character isLowerCase() method

public static boolean isLowerCase(char ch)
(or)
public static boolean isLowerCase(int codePoint)

Parameters

  • ch − the character to be tested

  • codePoint − the Unicode code point to be tested

Return Value

This method returns true if the character is lowercase, false otherwise.

Example

The following example shows the usage of Java Character isLowerCase(char ch) method.

package com.tutorialspoint;
import java.lang.*;
public class CharacterDemo {
   public static void main(String[] args) {

      // create 2 char primitives ch1, ch2
      char ch1, ch2;

      // assign values to ch1, ch2
      ch1 = 'A';
      ch2 = 'a';

      // create 2 boolean primitives b1, b2
      boolean b1, b2;

      // check if ch1, ch2 are in lowercase and assign results to b1, b2
      b1 = Character.isLowerCase(ch1);
      b2 = Character.isLowerCase(ch2);

      String str1 = ch1 + " is a lowercase character is " + b1;
      String str2 = ch2 + " is a lowercase character is " + b2;

      // print b1, b2 values
      System.out.println( str1 );
      System.out.println( str2 );
   }
}

Output

Let us compile and run the above program, this will produce the following result −

A is a lowercase character is false
a is a lowercase character is true

Example

The following example shows the usage of Java Character isLowerCase(int codePoint) method.

package com.tutorialspoint;
import java.lang.*;
public class CharacterDemo {
   public static void main(String[] args) {

      // create 2 int primitives cp1, cp2
      int cp1, cp2;

      // assign values to cp1, cp2
      cp1 = 0x007a;
      cp2 = 0x0fff;

      // create 2 boolean primitives b1, b2
      boolean b1, b2;

      /**
       *  check if cp1, cp2 represents lowercase characters
       *  and assign results to b1, b2
       */
      b1 = Character.isLowerCase(cp1);
      b2 = Character.isLowerCase(cp2);

      String str1 = "cp1 represents a lowercase character is " + b1;
      String str2 = "cp2 represents a lowercase character is " + b2;

      // print b1, b2 values
      System.out.println( str1 );
      System.out.println( str2 );
   }
}

Output

Let us compile and run the above program, this will produce the following result −

cp1 represents a lowercase character is true
cp2 represents a lowercase character is false

Example

Symbol and digit characters are not case-sensitive. Hence, in the following example, let us see how the method works if these characters are passed as arguments to it.

public class LowerCaseDemo{
   public static void main(String []args){
      char c1 = '$';
	   char c2 = '5';
      boolean b1 = Character.isLowerCase(c1);
      System.out.println(c1 + " is Lower Case : " + b1);
	   boolean b2 = Character.isLowerCase(c2);
      System.out.println(c2 + " is Lower Case : " + b2);
   }
}

Output

Once the program is compiled and run, the output will not throw an error even though symbols are not case sensitive. The method simply returns false.

$ is Lower Case : false
5 is Lower Case : false

Example

As the return type for this method is a boolean value, we can use the method as the condition to a conditional statement as well. The example is given below.

import java.lang.*;
public class IdentifierDemo {
   public static void main(String []args){
      char c = 'f';
      boolean b = Character.isLowerCase(c);
      if(b == true)
         System.out.println(c + " is a Lower Case Character");
      else
         System.out.println(c + " is not a Lower Case Character");
   }
}

Output

The program is first compiled and run, the output is then obtained as follows −

f is a Lower Case Character
java_lang_character.htm
Advertisements