devxlogo

Avoid NullPointerException in String Equality Comparison

Avoid NullPointerException in String Equality Comparison

In equal comparisons it is recommended to place literals first. This way you eliminate the risk of NullPointerException:

//avoid obj.equals("foo");//prefer"foo".equals(obj);

devx-admin

Share the Post: