How to Check for Empty String in Java

Not suprisingly most programming languages handle this check the same way. You have to check for null first to avoid a NullPointerException.

if (string == null || string.IsEmpty()) {
  //...
}

If you are using Spring just use StringUtils.isEmpty. Google’s Guava has Strings.isNullorEmpty. Or write your own.