Comparing strings in an if: !string.equals("") vs !"".equals(string)

java

Solution

`billAddress1.equals("")` will cause a NullPointerException if `billAddress1` is `null`, `"".equals(billAddress1)` wont.

Problem

Possible Duplicate: Difference between these two conditions? I am doing some code cleanup and NetBeans made a suggestion to change `if(!billAddress1.equals(""))` to `if (!"".equals(billAddress1))`. What is the difference between the two, and the advantages of using the suggested version over the readability of the original version?

Original source

Related problems