Signup/Sign In

Java Character lowSurrogate() Method

Java lowSurrogate() Method is a part of Character class. This method returns the trailing surrogate (a low surrogate code unit) of the surrogate pair representing the specified supplementary character (Unicode code point) in the UTF-16 encoding.

Syntax:

public static char lowSurrogate(int codePoint)

Parameters:

The parameter passed is the Unicode codepoint character whose trailing surrogate is to be returned.

Returns:

Returns the trailing surrogate code unit used to represent the specified codepoint character in the UTF-16 encoding.

Example 1:

Here, the trailing surrogate characters are returned for the specified Unicode codepoint characters.

public class StudyTonight
{  
	public static void main(String[] args)
	{  
		int cp1 = 67;  
		int cp2 = 88;  
		int cp3 = 119;  
		int cp4 = 202;   
		int cp5 = 1232;  

		char ch1 = Character.lowSurrogate(cp1);  
		char ch2 = Character.lowSurrogate(cp2);  
		char ch3 = Character.lowSurrogate(cp3);  
		char ch4 = Character.lowSurrogate(cp4);  
		char ch5 = Character.lowSurrogate(cp5);  

		System.out.println("The trailing surrogate for " +(char)cp1 +" is "+ch1);  
		System.out.println("The trailing surrogate for " +(char)cp2 +" is "+ch2);  
		System.out.println("The trailing surrogate for " +(char)cp3 +" is "+ch3);  
		System.out.println("The trailing surrogate for " +(char)cp4 +" is "+ch4);  
		System.out.println("The trailing surrogate for " +(char)cp5 +" is "+ch5);  
	}  
} 


The trailing surrogate for C is ?
The trailing surrogate for X is ?
The trailing surrogate for w is ?
The trailing surrogate for Ê is ?
The trailing surrogate for ? is ?

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 Unicode character: ");  
			Scanner sc = new Scanner(System.in);        
			int cp = sc.nextInt(); 
			char ch = Character.lowSurrogate(cp);
			System.out.println("The trailing surrogate for " +(char)cp +" is "+ch);
		}
		catch(Exception e)
		{
			System.out.println("Invalid Input!!");
		}
	}
}


Enter the Unicode character: 66
The trailing surrogate for B is ?
*****************************************
Enter the Unicode character: 34343
The trailing surrogate for ? is ?

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.



About the author:
A Computer Science and Engineering Graduate(2016-2020) from JSSATE Noida. JAVA is Love. Sincerely Followed Sachin Tendulkar as a child, M S Dhoni as a teenager, and Virat Kohli as an adult.