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.
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