I need to check if a String has multiple white space characters. I have written a program below to check if there are multiple white space characters in a particular string. But m.matches() always returning false and the string "Multiple White space characters" is not all getting displayed for any INPUT. Can some one please let me know where I'm doing wrong.
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexTest {
private static final String REGEX = "[ ]{2,}";
private static final String INPUT = "cat catcatcattiecat";
public static void main( String args[] ) {
Pattern p = Pattern.compile(REGEX);
Matcher m = p.matcher(INPUT);
if(m.matches())
System.out.println("Multiple White space characters");
}
}