Testing Equality with Strings
Doug Winnie · Apress eBooks · 2021
When comparing strings together, there are some issues that can come up. When you work with primitive local value types like int , float , etc., these are stored as values on the stack that have unique memory addresses from each other. When you work with class types, like String , they refer to memory locations on the heap. When you use the equality operator, == , it looks and returns true if the reference is equal between the two items. Sometimes, when you use class types, the references can be different, so this returns a false , even if the values in the strings are identical.