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

Question

can you please help me with thus question

Answer ( 1 )

    • == compares object references (memory addresses).
    • .equals() is used to compare content of objects.
    • Example:
      String a = new String("Hello");
      String b = new String("Hello");
      System.out.println(a == b); // false (different objects)
      System.out.println(a.equals(b)); // true (same content)

Leave an answer