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 Matches All

Char Matcher Matches All 

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.matchesAllOf() API. It returns TRUE if the given character sequence contains only matching characters.

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

import com.google.common.base.CharMatcher;

public class CharMatcherMatchesAllTest {

  /**
   @param args
   */
  public static void main(String[] args) {
    System.out.println(CharMatcher.DIGIT.matchesAllOf("123456"));
    System.out.println(CharMatcher.DIGIT.matchesAllOf("123456abc"));
    System.out.println(CharMatcher.DIGIT.matchesAllOf("abcdefg"));
    
    System.out.println(CharMatcher.JAVA_LETTER.matchesAllOf("abcdefg"));
    System.out.println(CharMatcher.JAVA_LETTER.matchesAllOf("123456abc"));
    System.out.println(CharMatcher.JAVA_LETTER.matchesAllOf("123456"));
    
    System.out.println(CharMatcher.JAVA_LETTER_OR_DIGIT.matchesAllOf("123456"));
    System.out.println(CharMatcher.JAVA_LETTER_OR_DIGIT.matchesAllOf("abcdefg"));
    System.out.println(CharMatcher.JAVA_LETTER_OR_DIGIT.matchesAllOf("123456abc"));
  }
}
   

It gives the following output,
true
false
false

true
false
false

true
true
true


                    Print

   



Books Recommendation

 
 
bl  br