Tuesday 5 January 2016

How to check if String is not null and empty in Java?

In Java, since null and empty are two different concept, it's a little bit tricky for beginners to check if a String is both not null and not empty. A String reference variable points to null if it has not been initialized and an empty String is a String without any character or a String of zero length. Remember, a String with just whitespace may not be considered as empty String by one program but considered as empty String by others, so, depending upon your situation, you can include the logic to check for that as well. A String with just white space is also referred as blank String in java. In this tutorial, I will teach you a couple of right ways to test if a String is not null and not empty in Java.
Read more »

No comments:

Post a Comment