Java.lang.Character.isSurrogatePair() Method

Advertisements


Description

The java.lang.Character.isSurrogatePair(char high, char low) determines whether the specified pair of char values is a valid Unicode surrogate pair.

Declaration

Following is the declaration for java.lang.Character.isSurrogatePair() method

public static boolean isSurrogatePair(char high, char low)

Parameters

  • high - the high-surrogate code value to be tested

  • low - the low-surrogate code value to be tested

Return Value

This method returns true if the specified high and low-surrogate code values represent a valid surrogate pair, false otherwise.

Exception

  • NA

Example

The following example shows the usage of lang.Character.isSurrogatePair() 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 = '\ud800';
      ch2 = '\udc00';

      // create a boolean primitive b
      boolean b;

      // check if ch1, ch2 is a surrogate pair and assign result to b
      b = Character.isSurrogatePair(ch1, ch2);

      String str = "ch1, ch2 is a valid Unicode surrogate pair is " + b;

      // print b value
      System.out.println( str );
   }
}

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

ch1, ch2 is a valid Unicode surrogate pair is true



Advertisements
Advertisements