This example will show how to check if a String is null or empty using java, guava and apache commons. A common error when working with Strings is a NullPointerException which is thrown when you try to use a reference of an object that points to no location in memory. In other words, you try to make a call to an object or method that doesn't exist. The technique shown below if used will help prevent these exceptions. If you are working with collections you should consider Effective Java Item 43: Return empty arrays or collections, not nulls.
Straight up Java
This snippet will show how to check if a String is null and its length is greater than zero to prevent a NullPointerException. This approach is effective but verbose and is often replaced by a utility shown below.
Check w/ String.length()
Check w/ String.isEmpty()
This snippet will show how to check if a string is null or empty with guava's Strings.isNullOrEmpty static utility.
Apache commons StringUtils.isNotEmpty will checks if a String is not empty and not null.