To check if a string contains spaces, use Matcher and call its find method.
Pattern pattern = Pattern.compile("\\s"); Matcher matcher = pattern.matcher(s); boolean found = matcher.find();
If you want to check if it consists only of spaces, you can use String.matches :
boolean isWhitespace = s.matches("^\\s*$");
Mark Byers Nov 01 '10 at 9:41 2010-11-01 09:41
source share