The difference between isBlank() and isEmpty() in Java
The main difference between these two string operations is this: isBlank()
accepts strings with only whitespace while isEmpty()
does not.
isBlank()
examples
"".isBlank() // true
" ".isBlank() // true
"hi".isBlank() // false
" hi ".isBlank() // false
isEmpty()
examples
"".isEmpty() // true
" ".isEmpty() // false
"hi".isEmpty() // false
" hi ".isEmpty() // false
StringUtils
operates the same way, except it will returntrue
fornull
inputs (e.g.StringUtils.isEmpty(null)
andStringUtils.isBlank(null)
aretrue
).