if ( str != null && str.trim().length() > 0 )
...
Wouldn't it be neat if JDK will just say
if ( !str.isEmpty() )
...
you can. I have methods for doing that as part of common11.
the confusion between null and "" shipwrecks many a program.
See
http://mindprod.com/jgloss/void.html
Here are some:
/**
* Convert String to canonical standard form. null -> "". Trims
lead trail
* blanks.
*
* @param s
* String to be converted.
* @return String in canonical form.
*/
public final static String canonical ( String s )
{
if ( s == null )
return "";
else
return s.trim();
} // end canonical
/**
* Is this string empty?
*
* @param s
* String to be tested for emptiness.
* @return true if the string is null or equal to the "" null
string. or
* just blanks
*/
public final static boolean isEmpty ( String s )
{
return ( s == null ) ? true : s.trim().length() == 0;
} // end isEmpty