`==` dla obiektów porównuje referencje (czy to ta sama instancja), a `.equals()` porównuje równość logiczną zdefiniowaną przez klasę (np. `String` porównuje treść). Dla typów prostych `==` porównuje wartości.
String a = new String("hi");
String b = new String("hi");
System.out.println(a == b); // false
System.out.println(a.equals(b)); // trueDla prymitywów (`int`, `long`, `boolean`) `==` porównuje wartości.
Dla obiektów (`String`, `Integer`, własne klasy) `==` sprawdza *tożsamość* (ta sama instancja), a `.equals()` sprawdza *równość logiczną* (ta sama treść/stan) zgodnie z implementacją klasy.
Integer a = 128, b = 128;
System.out.println(a == b); // często false (różne obiekty)
System.out.println(a.equals(b)); // true
String s1 = "hi";
String s2 = new String("hi");
System.out.println(s1 == s2); // false
System.out.println(s1.equals(s2));// true