The java.lang.Character.charCount() is an inbuilt function in java which is used to determine number of characters needed to represent the specified character. If the character is equal to or greater than 0x10000, the method returns 2 otherwise 1.
public static int charCount(int code)
Parameters: The function accepts a single parameter code. It represents the tested character.
Return Value: It returns 2 if the character is valid otherwise 1.
Errors and Exceptions:
- This method doesn’t validate the specified character to be a valid Unicode code point.
- Non-static method is can be called by declaring method_name(argv) in this such case method is static, it should be called by adding the class name as the suffix. We will be get a compilation problem if we call charCount method non-statically.
Input : 0x12456 Output : 2 Explanation: the code is greater than 0x10000 Input : 0x9456 Output : 1 Explanation: The code is smaller then 0x10000
Below Programs illustrates the java.lang.Character.charCount() function:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Character.valueOf() in Java with examples
- Character.isIdentifierIgnorable() in Java with Examples
- Character.reverseBytes() in Java with examples
- Character.digit() in Java with examples
- Character.hashCode() in Java with examples
- Character.isMirrored() in Java with examples
- Character.isLetterOrDigit() in Java with examples
- Character.isTitleCase() in Java with examples
- Character.offsetByCodePoints() in Java with Examples
- Character.charValue() in Java with examples
- Character.getDirectionality() method in Java with examples
- Character.isUnicodeIdentifierPart() Method in Java with Examples
- Character.isWhitespace() method in Java with examples
- Character.equals() method in Java with examples
- Character.isISOControl() method with examples in Java
- Character.isHighSurrogate() method in Java with examples
- Character getType() Method in Java with examples
- Character.isLowSurrogate() method in Java with examples
- Character.isJavaIdentifierPart() Method in Java with Examples
- Character.isValidCodePoint() Method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.