December 5, 2017

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); Related Articles Using the “==” Operator with Double or Float