Java.lang.Character.toCodePoint() Method
Advertisements
Description
The java.lang.Character.toCodePoint(char high, char low) converts the specified surrogate pair to its supplementary code point value. This method does not validate the specified surrogate pair. The caller must validate it using isSurrogatePair if necessary.
Declaration
Following is the declaration for java.lang.Character.toCodePoint() method
public static int toCodePoint(char high, char low)
Parameters
high - the high-surrogate code unit
low - the low-surrogate code unit
Return Value
This method returns the supplementary code point composed from the specified surrogate pair.
Exception
NA
Example
The following example shows the usage of lang.Character.toCodePoint() 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 an int primitive cp
int cp;
// assign code point value of surrogate pair ch1, ch2 to cp
cp = Character.toCodePoint(ch1, ch2);
String str = "Supplementary code point value is " + cp;
// print cp value
System.out.println( str );
}
}
Let us compile and run the above program, this will produce the following result:
Supplementary code point value is 65536