Sobes.tech
Senior

Can you give a similar example with another type where '==' will give false?

sobes.tech AI

Answer from AI

In Java, the == operator for objects compares references, not content. Here's an example with another type where == will return false, even if the objects are logically equal:

Integer a = new Integer(1000);
Integer b = new Integer(1000);
System.out.println(a == b); // false, different objects
System.out.println(a.equals(b)); // true, values are equal

Here, two Integer objects with the same value, but == compares references, so the result is false. The same applies to any objects if equals is not overridden or if primitives are not compared.