Which operator is used in Java to compare two string objects for equality?

  • !=
  • .equals()
  • ==
  • compare()
In Java, you should use the .equals() method to compare the contents of two string objects for equality. The == operator, on the other hand, checks whether the two string objects are the same object in memory, which is not the same as comparing their content. The other options are not the recommended way to compare strings for equality.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *