One can use == operators for reference comparison (address comparison) and . equals() method for content comparison. In simple words, == checks if both objects point to the same memory location whereas .
Read moreCan you use == to compare objects?
In Java, the == operator compares that two references are identical or not . Whereas the equals() method compares two objects. Objects are equal when they have the same state (usually comparing variables).
Read moreWhy can’t you use == for strings in Java?
Do not use the == operator to compare Strings operators. These operators actually test references, and since multiple String objects can represent the same String , this is liable to give the wrong answer. Instead, use the String.
Read more