Comparing a string with the empty string (Java)
s1 == “” is not reliable as it tests reference equality not object equality (and String isn’t strictly canonical). s1.equals(“”) is better but can suffer from null pointer exceptions. Better yet is: “”.equals(s1) No null pointer exceptions. EDIT: Ok, the point was asked about canonical form. This article defines it as: Suppose we have some … Read more