Checking if a string is empty or null in Java [duplicate]

Correct way to check for null or empty or string containing only spaces is like this:

if(str != null && !str.trim().isEmpty()) { /* do your stuffs here */ }

Leave a Comment