Determines whether two String objects contain the same data.
public boolean equals(Object obj)
Parameters
|
Parameter
|
Description
|
| obj | A java.lang.String object to compare against the current String for equality. |
Property Value/Return Value
true if the two String objects contain the same data; false otherwise.
// string_equals.jsl
public class Program
{
public static void main(String[] args)
{
String physicist1 = "Albert Einstein";
String physicist2 = "Max Planck";
String physicist3 = "Albert Einstein";
// Are any of the above Strings equal to one another?
boolean equals1 = physicist1.equals(physicist2);
boolean equals2 = physicist1.equals(physicist3);
// Display the results of the equality checks.
System.out.println("\"" + physicist1 + "\" equals \"" +
physicist2 + "\"? " + equals1);
System.out.println("\"" + physicist1 + "\" equals \"" +
physicist3 + "\"? " + equals2);
}
}
/*
Output:
"Albert Einstein" equals "Max Planck"? false
"Albert Einstein" equals "Albert Einstein"? true
*/
Reference
java.lang.String