Strings, just like any other ``++Object++``, should be compared using the ``++equals()++`` method.

Using ``++==++`` or ``++!=++`` compares references rather than values, and usually does not work.


== Noncompliant Code Example

----
if (variable == "foo") { /* ... */ }
if (variable != "foo") { /* ... */ }
----


== Compliant Solution

----
if ("foo".equals(variable)) { /* ... */ }
if (!"foo".equals(variable)) { /* ... */ }
----


== See

* http://cwe.mitre.org/data/definitions/597.html[MITRE, CWE-597] - Use of Wrong Operator in String Comparison

