Essentially, only PDTs can be checked with ==. These are byte, short, int, long, float, double, boolean, char and of course, references. As the two references you get are different objects, the result would be false.
For any ADT (or object), you have to make use of the equals() method. All Java objects have them and you have to implement it for your own objects as well. For the String object this has been done for you and the characters are compared for to test equality.
No comments:
Post a Comment