intermediateCore Java Fundamentals37 of 436

Difference between == and .equals()?

Tests whether you know == compares references (or primitive values) while .equals() compares logical/content equality as defined by the class -- and that unboxed Integer caching (-128 to 127) is the classic trap that makes == appear to 'work' until it doesn't.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

← Back to all Core Java questions