Generally . equals is used for Object comparison , where you want to verify if two Objects have an identical value. == for reference comparison (are the two Objects the same Object on the heap) & to check if the Object is null.20 Nis 2009
Read moreCan I use == to compare strings in Java?
To compare these strings in Java, we need to use the equals() method of the string. You should not use == (equality operator) to compare these strings because they compare the reference of the string , i.e. whether they are the same object or not.
Read more