JavaBeginner#operators#object

What is the difference between == and equals() in Java?

== compares references (memory addresses) for objects and values for primitives. equals() is a method that compares the actual content. By default Object.equals() behaves like ==, but classes like String and Integer override it to compare values.

Example
String a = new String("hi");
String b = new String("hi");
a == b;        // false (different objects)
a.equals(b);   // true (same content)

Related Questions

1
JavaBeginner#oop

Explain OOP principles in Java.

Open
2
JavaIntermediate#oop#interface

What is the difference between abstract class and interface?

Open
3
JavaBeginner#oop#polymorphism

What is method overloading vs overriding?

Open