Skip to content

Q 19 - == vs .equal() #23

Discussion options

You must be logged in to vote

In Java:

  • "==" checks for reference equality (i.e., both objects point to the same memory location).
  • ".equals()" checks for content equality (i.e., the contents of both objects are the same).

Example:

String s1 = new String("Hello");
String s2 = new String("Hello");

System.out.println(s1 == s2); // false (different references)
System.out.println(s1.equals(s2)); // true (same content)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by HARSHITH-MV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants