java.lang.Character.toChars(int codePoint, char[] dst, int dstIndex)


java.lang.Character.toChars(int codePoint, char[] dst, int dstIndex)

package com.codingdict;



import java.lang.*;



public class CharacterDemo {



   public static void main(String[] args) {



      // create an int primitive cp and assign value

      int cp = 0x0036;



      // create an int primitive res

      int res;



      /**

       *  create a char array dst and assign UTF-16 value of cp

       *  to it using toChars method

       */

      char dst[] = Character.toChars(cp);



      // check if cp is BMP or supplementary code point using toChars

      res = Character.toChars(cp, dst, 0);



      String str1 = "It is a BMP code point";

      String str2 = "It is a is a supplementary code point";



      // print res value

      if ( res == 1 ) {

         System.out.println( str1 );

      } else if ( res == 2 ) {

         System.out.println( str2 );

      }

   }

}