String.equals()should be used when checking value equality on String literals. Using
!=compares object references, not the actual value of the Strings. This only modifies code where at least one side of the binary operation (
!=) is a String literal, such as
"someString" == someVariable;. This is to prevent inadvertently changing code where referential equality is the user's intent.