Java Character toChars() Method6 Nov 2024 | 3 min read The 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 |
The isJavaIdentifierStart(char ch) method of Character class determines whether the given(or specified) character is considered as the first character in a Java identifier or not. A character may start a Java identifier if and only if any of the following conditions is true: isLetter(ch) returns true. getType(ch) returns LETTER_NUMBER. The...
4 min read
The getType(char ch) method of Character class returns a value which indicates the general category of the character. This method is not used for the supplementary characters. We can use the getType(int codePoint) method to support all the Unicode characters including the supplementary. Syntax public static int getType(char...
4 min read
The compare(char x, char y) method of Character class is used to compare two char values numerically. The final value returned is similar to what would be returned by: Character.valueoOf(x).compareTo(Character.valueOf(y)) Syntax public static intcompare(char x, char y) Parameter The above method requires two parameters: char x which is the first character to...
2 min read
The Character.isUnicodeIdentifierPart() method in Java checks if a given character is valid as part of a Unicode identifier. It evaluates whether the character can legally appear after the first character in identifiers, based on Unicode rules, ensuring it's a letter, digit, connecting character, or part of...
8 min read
The toString() method of Character class returns the String object which represents the given Character's value. The obtained result is typically a string with length 1 whose component is a primitive char value that represents the Character object. Syntax public String toString() Return Value The toString()method returns the string representation...
4 min read
The isDefined(char ch) method of Character class generally determines whether the character is defined in the Unicode or not. A character is defined in Unicode if and only if any of the two conditions are satisfied(or true): The character must have an entry made in the UnicodeData file. The...
4 min read
The forDigit(int digit, int radix) method of character class determines the character representation for a specific digit in the specified radix. If the value of the digit is not a valid digit in the specified radix or if the value of the radix is not a...
3 min read
The isJavaLetterOrDigit(char ch) method of Character class determines whether the given(or specified) character can be a part of Java identifier as other than the first character. A character is a part of Java identifier if and only if any of the following conditions is true: The character is...
3 min read
Java Character.isUnicodeIdentifierStart() is a method of the Character class and helps find valid starting characters for Unicode identifiers. When coding, we have to follow rules referring to Identifiers names, variable names and class names as well as method names in order that the program has...
5 min read
The isIdentifierIgnorable(int codePoint) method of Character class generally determines whether the specified character can be considered as an ignorable character in Java or a Unicode identifier. The following characters are considered as ignorable characters in Java or Unicode identifier: ISO control characters which do not have whitespace. All the...
4 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India