What is the difference between `==` and `.equals()` when comparing String objects in Java?

Java Associate Medium

Java Associate — Medium

What is the difference between `==` and `.equals()` when comparing String objects in Java?

Key points

  • `==` checks references, while `.equals()` checks content
  • Using `==` with Strings may not give the expected result
  • Always use `.equals()` when comparing String objects

Ready to go further?

Related questions