CharMatcher Class | Guava | Java Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report CharMatcher determines a true or false value for any Java char value. This class provides various methods to handle various Java types for char values. Declaration: The declaration for com.google.common.base.CharMatcher is as: @GwtCompatible(emulated = true) public final class CharMatcher extends Object There are 2 ways to obtain CharMatcher instance: Using constants: CharMatcher class provides following constants to obtain CharMatcher instance. Note : This class deals only with char values. It does not understand supplementary Unicode code points in the range 0x10000 to 0x10FFFF. Such logical characters are encoded into a String using surrogate pairs, and a CharMatcher treats these just as two separate characters. Using methods provided by CharMatcher class: One can get instance of CharMatcher class by using following methods. Example 1: Java // Java code to get number of matching // characters in given sequence // and display them using countIn() import com.google.common.base.CharMatcher; class GFG { // Driver code public static void main(String args[]) { // "anyOf" method returns a char matcher // that matches any character present in // the given character sequence. CharMatcher matcher = CharMatcher.anyOf("aeiou"); String str = "Hello GeeksforGeeks, What's up ?"; // "countIn" returns the number of matching // characters found in a character sequence. int vowels = matcher.countIn(str); // To display the number of vowels in // character sequence System.out.println("Number of vowels in '" + str + "' are " + vowels); } } Output: Number of vowels in 'Hello GeeksforGeeks, What's up ?' are 9 Some other methods of CharMatcher Class are: Example 2: Java // Java code to get the index // of matching character import com.google.common.base.CharMatcher; class GFG { // Driver code public static void main(String args[]) { // "anyOf" method returns a char matcher // that matches any character present in // the given character sequence. CharMatcher matcher = CharMatcher.anyOf("aeiou"); String str = "Hello GeeksforGeeks, What's up ?"; // To return the index of first matching // character in given input sequence. int firstIndex = matcher.indexIn(str); // To Return the index of first matching // character in given input sequence, // from given starting index. int nextIndex = matcher.indexIn(str, firstIndex + 1); // To return the index of the last matching // character in a character sequence int lastIndex = matcher.lastIndexIn(str); System.out.println("First Index is " + firstIndex); System.out.println("Next Index is " + nextIndex); System.out.println("Last Index is " + lastIndex); } } Output: First Index is 1 Next Index is 4 Last Index is 28 Some other methods of CharMatcher Class are: Example 3: Java // Java code to remove all digits // from a given string import com.google.common.base.CharMatcher; class GFG { // Driver code public static void main(String args[]) { // Determines whether a character is // a digit according to Unicode. CharMatcher matcher = CharMatcher.DIGIT; String str = "12345Hello GeeksforGeeks1287 What's 9886up"; System.out.println("Original String : " + str); // To remove all matching characters // from given string. String result = matcher.removeFrom(str); // To display the string which // doesn't contain digit System.out.println("After digit removal : " + result); } } Output: Original String : 12345Hello GeeksforGeeks1287 What's 9886up After digit removal : Hello GeeksforGeeks What's up Reference: Google Guava Comment More infoAdvertise with us Next Article Chars Class | Guava | Java S Sahil_Bansall Follow Improve Article Tags : Java java-guava Practice Tags : Java Similar Reads Chars Class | Guava | Java Chars is a utility class for primitive type char. It provides Static utility methods pertaining to char primitives, that are not already found in either Character or Arrays. All the operations in this class treat char values strictly numerically, i.e, they are neither Unicode-aware nor locale-depend 3 min read CaseFormat Class | Guava | Java CaseFormat is a utility class for converting between various ASCII case formats. Behavior is undefined for non-ASCII input. Declaration: The declaration for com.google.common.base.CaseFormat is as: @GwtCompatible public enum CaseFormat extends Enum Below table gives the summary of Enum Constants and 2 min read Bytes Class | Guava | Java Bytes is a utility class for primitive type byte. It provides Static utility methods pertaining to byte primitives, that are not already found in either Byte or Arrays and interpret bytes as neither signed nor unsigned. The methods which specifically treat bytes as signed or unsigned are found in Si 3 min read BigIntegerMath Class | Guava | Java BigIntegerMath is used to perform mathematical operations on BigInteger values. Basic standalone math functions are divided into the classes IntMath, LongMath, DoubleMath, and BigIntegerMath based on the primary numeric type involved. These classes have parallel structure, but each supports only the 3 min read CharMatcher fields with Examples | Guava | Java CharMatcher class provides the following constants to obtain CharMatcher instance. Below are some of them DIGIT CharMatcher.DIGIT determines whether a character is a digit according to Unicode. If you only care to match ASCII digits, you can use inRange('0', '9'). Syntax: public static final CharMat 5 min read CharsetDecoder Class in Java For encoding and decoding tasks, many methods are offered in Charset Encoder and Charset Decoder classes in Java. The Charset Decoder class is used for text handling to convert bytes to characters. The Charset decoder accepts a sequence of bytes as its input and displays Unicode characters as output 5 min read Like