Java Character charCount() with Examples Last Updated : 14 Dec, 2022 Comments Improve Suggest changes Like Article Like Report 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. Syntax: 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. Examples: Input : 0x12456 Output : 2 Explanation: the code is greater than 0x10000 Input : 0x9456 Output : 1 Explanation: The code is smaller than 0x10000 Below Programs illustrates the java.lang.Character.charCount() function: Program 1: Java // Java program that demonstrates the use of // Character.charCount() function // include lang package import java.lang.*; class GFG { public static void main(String[] args) { int code = 0x9000; int ans = Character.charCount(code); // prints 2 if character is greater than 0x10000 // otherwise 1 System.out.println(ans); } } Output:1 Program 2: Java // Java program that demonstrates the use of // Character.charCount() function // include lang package import java.lang.*; class GFG { public static void main(String[] args) { int code = 0x12456; int ans = Character.charCount(code); // prints 2 if character is greater than 0x10000 // otherwise 1 System.out.println(ans); } } Output:2 Comment More infoAdvertise with us A akash1295 Follow Improve Article Tags : Java Java-lang package Java-Functions Java-Character Practice Tags : Java Explore BasicsIntroduction to Java4 min readJava Programming Basics9 min readJava Methods7 min readAccess Modifiers in Java6 min readArrays in Java9 min readJava Strings8 min readRegular Expressions in Java7 min readOOPs & InterfacesClasses and Objects in Java10 min readJava Constructors10 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface11 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java6 min readIterator in Java5 min readJava Comparator Interface6 min readException HandlingJava Exception Handling8 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java10 min readFile Handling in Java5 min readJava Method References9 min readJava 8 Stream Tutorial15+ min readJava Networking15+ min readJDBC Tutorial12 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples8 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions7 min readJava Quiz | Level Up Your Java Skills1 min readTop 50 Java Project Ideas For Beginners and Advanced [Update 2025]15+ min read Like