SyntaxHighlighter JS

2013-01-13

Null safe string equals

Instead of
if ( str != null && str.equals("TheString") ) 

use
if ( "TheString".equals(str) ) 

The second form is more concise and will return false if str is null.

No comments:

Post a Comment