Java - Character lowSurrogate() Method



Description

The Java Character lowSurrogate() method accepts a code point as an argument and returns the low or trailing surrogate value of the surrogate pair that represents a supplementary character in UTF-16 encoding. If the code point is not a valid supplementary code point, an unspecified char value will be returned.

This method is a static method, hence, it can be invoked using the class name as its prefix without creating the instance of the class.

Syntax

Following is the syntax of the Java Character lowSurrogate() method

public static char lowSurrogate(int codePoint)

Parameters

  • codePoint − a supplementary character

Return Value

This method returns a trailing surrogate character that represents the supplementary character argument.

Getting a Low Surrogate Char from a CodePoint Example

The following example shows the usage of the Java Character lowSurrogate() method. In this program, we've created a int variable and initialized with a hexa decimal value and using lowSurrogate() method, we've retrieved the trailing or low surrogate char and result is printed.

package com.tutorialspoint;

public class lowSurrogateDemo {
   public static void main(String args[]) {
      int cp;
      char ls;
      cp = 0x10FFFF;
      ls = Character.lowSurrogate(cp);
      System.out.println("The low surrogate character is: " + ls);
   }
}

Output

The output of the program above is as follows −

The low surrogate character is: ?

Getting a Low Surrogate Char from a non-supplementary CodePoint Example

If the code point passed as an argument is not a supplementary code point, the method will return an unspecified char value.

package com.tutorialspoint;

public class lowSurrogateDemo {
   public static void main(String args[]) {
      int cp;
      char ls;
      cp = 0x1023;
      ls = Character. lowSurrogate(cp);
      System.out.println("The low surrogate character is: " + ls);
   }
}

Output

If we compile and run the above program, the output is displayed as follows −

The low surrogate character is: ?

Getting a Low Surrogate Char from an invalid CodePoint Example

Now let us see an example where we pass an invalid code point value as an argument to the method.

package com.tutorialspoint;

public class lowSurrogateDemo {
   public static void main(String args[]) {
      int cp;
      char ls;
      cp = 82241244;
      ls = Character.lowSurrogate(cp);
      System.out.println("The low surrogate character is: " + ls);
   }
}

Output

When we compile and run the above program, the output is shown as follows −

The low surrogate character is: ?
java_lang_character.htm
Advertisements