I am a little confused, I learned that String
s are objects, therefore to compare them you should use String#equals
.
My question is: if I have a String
as an attribute, is it an object?
To clarify my question:
Class A {
public String nom;
A(nom) {
this.nom = nom;
}
}
... and in the main method:
A a = new A("Sara");
A b = new A("Youssef");
A c = new A("Sara");
a.nom == b.nom; ==> false
a.nom == c.nom; ==> true
Therefore, is the comparison of String
s' values more like c++, i.e. not about their references?