Online Java Compiler By
JavaTpoint.com
public class JavaCharactertoCharsExample1 { public static void main(String[] args) { // Create two integer primitives cp1 and cp2 and then assign the values. int cp1 = 0x0090; int cp2 = 0x0044; // Create two integer primitives result1 and result2. int result1, result2; // Create two char array ch1 and ch2. char ch1[] = Character.toChars(cp1); char ch2[] = Character.toChars(cp2); // Check whether the primitives are BMP or supplementary code point using toChars(). result1 = Character.toChars(cp1, ch1, 0); result2 = Character.toChars(cp2, ch2, 0); String str1 = "The primitive is a BMP code point."; String str2 = "The primitive is a supplementary code point."; // print res value if ( result1 == 1 ) { System.out.println( str1 ); } else if ( result1 == 2 ) { System.out.println( str2 ); } if ( result2 == 1 ) { System.out.println( str1 ); } else if ( result2 == 2 ) { System.out.println( str2 ); } } }
Output