In Java, == and .equals() serve different purposes:
== (Reference Comparison): This checks whether two variables point to the same memory location. If two objects have the same reference, == returns true.
.equals() (Value Comparison): This method is used to compare the actual content of objects. For example, when comparing two String objects, .equals() checks whether their text values are the same.
Example:
String a = new String("hello");
String b = new String("hello");
System.out.println(a == b); // false (different memory locations)
System.out.println(a.equals(b)); // true (same content)
Subscribe for more such videos.
Auf dieser Seite können Sie das Online-Video Java - String == (Reference Comparison) vs .equals() (Value Comparison) mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Khan's Tech Lab 13 April 2025 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 21 Mal angesehen und es wurde von 2 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!