Java Character isLowSurrogate() Method

Java isLowSurrogate() method is a part of Character class. This method is used to check whether the specified character is a low-surrogate code unit(trailing surrogate code unit) or not.

It must be noted that these values can be used to represent supplementary characters in the UTF-16 encoding and cannot be used to represent the characters by themselves.

Syntax:

public static boolean isLowSurrogate(char ch)  

Parameters:

The parameter passed is the character to be checked for the low-surrogate code unit.

Returns:

Returns the boolean value true if the char value is between MIN_LOW_SURROGATE and MAX_LOW_SURROGATE inclusive else returns false.

Example 1:

Here, the characters are checked whether they are low-surrogate code units or not.

public class StudyTonight
{  
	public static void main(String[] args)
	{  
		char ch1 = 'A';  
		char ch2 = 'u';  
		char ch3 = '\udc34';  
		char ch4 = '4';  
		char ch5 = '*';  

		boolean b1 = Character.isLowSurrogate(ch1);  
		boolean b2 = Character.isLowSurrogate(ch2);  
		boolean b3 = Character.isLowSurrogate(ch3);  
		boolean b4 = Character.isLowSurrogate(ch4);  
		boolean b5 = Character.isLowSurrogate(ch5);  

		System.out.println(ch1 +" is a low-surrogate?:  "+b1);  
		System.out.println(ch2 +" is a low-surrogate?:  "+b2);  
		System.out.println(ch3 +" is a low-surrogate?:  "+b3);  
		System.out.println(ch4 +" is a low-surrogate? : "+b4);  
		System.out.println(ch5 +" is a low-surrogate?:  "+b5);  
	}  
} 


A is a low-surrogate?: false
u is a low-surrogate?: false
? is a low-surrogate?: true
4 is a low-surrogate? : false
* is a low-surrogate?: false

Example 2:

Here is a user-defined example where anyone using this code can put a value of his choice and get the equivalent output.

import java.util.Scanner; 
public class StudyTonight
{  
	public static void main(String[] args)
	{  
		try
		{
			System.out.print("Enter the character ");  
			Scanner sc = new Scanner(System.in);         
			char ch = sc.next().charAt(0);  
			boolean b = Character.isLowSurrogate(ch);
			System.out.println(ch + " is a low-surrogate? : "+b);
		}
		catch(Exception e)
		{
			System.out.println("Invalid Input!!");
		}
	}  
}


Enter the character m
m is a low-surrogate? : false
***********************************
Enter the character *
* is a low-surrogate? : false

Live Example:

Here, you can test the live code example. You can execute the example for different values, even can edit and write your examples to test the Java code.