Java SE API
String.equals(Object)
In java.lang.String (java.base), tests whether the argument is a String with matching character sequence. A null argument returns false. A null receiver cannot invoke the method. No import is needed.
Formal Syntax & Structure
java syntaxjava
public boolean equals(Object anObject)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| anObject | java.lang.Object | Object to compare, including null. |
Return Value
boolean
True if the argument is a String with equal contents.
Working Example
Example Snippetjava
public class Main { public static void main(String[] args) { System.out.println("Bin 7".equals(new String("Bin 7"))); System.out.println("Bin 7".equals("bin 7")); }}