Question: how to check if a string contains whitespace in java?
Answer: Get the String to be checked in str.
We can use the trim() method of String class to remove the leading whitespaces in the string. ... 
Then we can use the isEmpty() method of String class to check if the resultant string is empty or not. ... 
Combine the use of both methods using Method Chaining.