== references to memory location, i.e if the both the objects share the same memory
.equals(...) references to the value of the object i.e if the both the objects has the exactly the same value.
Example: String name = "Smit";
In the memory | name || Smit |
So whenever a new literal is created, Java(JVM) will go a check for its existance in the mrmory and it there is no, it will create new.
name = "Smit Shah";
In the memory |name || Smit| | name || Smit Shah|
so everytime program makes changes to the String variable, it will create a new instance in the memory and it will cause HEAP size to increase