Objects and References: The special case of String
Caution: In the next few slides, we will cover what is one of the more confusing part of Java for new students. If you get lost, just remember what we’ve covered so far:
1. When comparing primitives (int, float, etc.), use ‘==‘
2. When comparing objects (String, or any class you create), use the equals() method.
3. When you create a class that
serves as a data type or record,
In the slides ahead we will note some
rare exceptions where the ‘==‘
comparison will work for objects.