Comparing Objects with the Equals Method
Comparing Objects
To compare objects, you will want to use a method. The equals
method, which is avaiable for all classes, can be used. Not all classes have a specific implementation of the equals
method, so you will want to look at the API to see if there is an implementation for the class.
String Class Equals Method
boolean equals(Object anObject)
This method returns
true
if the value of this String
is the same as the String
value of anObject
. NOTE: All classes extend the Object
class, meaning a String
is an Object
.
false
if the value of this String
is not the same as theString
value of anObject
.
LocalDate Class Equals Method
boolean equals(Object obj)
This method returns
true
if the value of this LocalDate
has the same date as obj
.
false
if the value of this LocalDate
does not have the same date as obj
.
Resources