• ==: Compares memory addresses (reference equality). For objects, it checks if they point to the same location in memory. Example: str1 == str2 checks if both references are the same object.

  • equals(): Compares the actual content (value equality). It is overridden in many classes like String to compare logical equality. Example: str1.equals(str2) checks if the values of str1 and str2 are identical.

In short: Use == for reference comparison and equals() for content comparison.