Sometimes `==` works on Strings in my code and sometimes it doesn't, which makes it hard to tell what the exam wants.
Accepted answer
`==` compares *references* (are these the same object in memory?), while `.equals()` compares *contents* (do these hold the same characters?).
`==` appears to work sometimes because Java interns string literals: two identical literals can point at the same object. But a String built at runtime — from concatenation, `new String(...)`, or user input — is a different object, so `==` is false even when the text matches.
Always use `.equals()` for String content. Reserve `==` for primitives and for genuine "same object" or `null` checks.