Groovy Goodness: Check if a String Only Contains Whitespaces
Join the DZone community and get the full member experience.Join For Free
In Groovy we can check if a
String value only contains whitespaces with the
isAllWhitespace() method. The method checks for spaces, but also takes into account tab and newline characters as whitespace.
assert ''.allWhitespace assert ' '.allWhitespace assert '\t '.allWhitespace assert ' \r\n '.allWhitespace assert !'mrhaki'.allWhitespace
Published at DZone with permission of Hubert Klein Ikkink, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.