0

I'm relatively new to Java so I'm kind of lost here. Is it wrong when you are trying to compare two strings just use the identical symbol "==" instead of using a method for checking if two strings are identical. Because for what I have tried the first option doesn't work and I'm very curious on the reason behing it

Mr. Spock
  • 29
  • 2

1 Answers1

0

In java when you use String, you work with reference.

String one = "one";
String two = "two";

if(one == two)
    // true if references `one` and `two` point to the same object

if(one.equals(two))
    // true if strings `one` and `two` are equals (it could be to different objects)
Oleg Cherednik
  • 17,377
  • 4
  • 21
  • 35