tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Tools and Libs > Google Guava > Basic > Char Matcher Count In

Char Matcher Count In 

Google Guava is a java library with lot of utilities and reusable components. This requires the library guava-10.0.jar to be in classpath. The following example shows using CharMatcher.countIn() API. It returns the count of matching characters in the given char sequence.

File Name  :  
com/bethecoder/tutorials/guava/base_tests/CharMatcherCountTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.guava.base_tests;

import com.google.common.base.CharMatcher;

public class CharMatcherCountTest {

  /**
   @param args
   */
  public static void main(String[] args) {
    System.out.println("Digit count : " + CharMatcher.DIGIT.countIn("ABC 1234"));
    System.out.println("Char count : " + CharMatcher.JAVA_LETTER.countIn("ABC 1234"));
    System.out.println("Char and digit count : " 
        CharMatcher.JAVA_LETTER_OR_DIGIT.countIn("ABC 1234"));
  }

}
   

It gives the following output,
Digit count : 4
Char count : 3
Char and digit count : 7


                    Print

   



Books Recommendation

 
 
bl  br