0
In java why do you have to use String.equals() for equivalence. Why cant you use == like the other data types?
2 Réponses
+ 5
Alvaro is right. Sometimes you need to compare whether two objects are the same objects (==), sometimes you have to check if they are equals although they are not the same (equals).
+ 4
AFAIK strings are stored roughly as objects. When you compare two objects via ==, you're not comparing the actual contents of the objects, but the respective pointers instead. That is, a==b evaluates whether a and b point to *the same* object (aka String). In order to compare the actual contents, you need .equals().