How to find white spaces in java string ?

Problem: Given string is "geek labs", now the problem is how to find is there any white spaces available in given string input?

Solution:

String name = "geek labs"

		
Pattern whiteSpacePattern = Pattern.compile("\\s"); Matcher matchIn = pattern.matcher(name); boolean isWhiteSpaceExist = matcher.find();

In above code snippet, pattern predefined character '\s' will check for a whitespace character: [ \t\n\x0B\f\r] in given matched string.

To know more about these predefined characters, folow this link

HTML Comment Box is loading comments...