Java Character toChars() MethodThe toChars(int codePoint) method of Character class generally converts the specified character into its UTF-16 representation which is usually stored in a char array. If the specified codePoint is a BMP value, the resulting char value array has the same value as the codePoint. On the other hand, if the specified codePoint is a supplementary codePoint, then the resulting char array contains the corresponding surrogate pair. SyntaxParametercodePoint: It is the codePoint which is the character that needs to be tested. Return ValueThe toChars(int codePoint)method returns the char array which has the UTF-16 representation of the character. Example 1Output: The char array with the UTF-16 representation is given as: n Example 2Output: The char array with the UTF-16 representation is given as: o Java Character toChars(int codePoint, char[] dst, int dstIndex)MethodThe toChars(int codePoint, char[] dst, int dstIndex) method of Character class converts the specified character into their respective UTF-16 representation. If the specified codePoint is BMP(Basic Multilingual Plane) codePoint value, the obtained value is stored in the dstIndex, and 1 is returned. On the other hand, if the specified codePoint is a supplementary character, the obtained surrogate value is stored in the dstIndex, and 1 is returned. SyntaxParameterThe above method requires three parameters: a.)The codePoint which is the character that needs to be tested. b.)The dst which is an array of character in which the UTF-16 value of the codePoint is stored. c.)The dstIndex is generally the start index of the dst array in which the converted value is stored. ReturnsThe toChars(int codePoint, char[] dst, int dstIndex)method returns 1 if the desired codePoint is a BMP codePoint. Otherwise, the method returns 2 if the desired codePoint is a supplementary codePoint. Example 1Output: The primitive is a BMP code point. The primitive is a BMP code point. Example 2Output: The primitive is a BMP code point. Next TopicJava-character-tocodepoint-method |