Checking if a string is empty or null in Java

The Solution to Checking if a string is empty or null in Java is


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 */ }

~ Answered on 2013-02-06 04:14:37


Most Viewed Questions: