How to compare strings in Java ?
Response by CodeGuy
Sometimes JAVA if == compares values, because it does some behind-the-scenes stuff but .equals() method always compares a value of String :
String a="Test";
String b="Test";
if(a.equals(b)) ===> true
String a="test";
String b=new String("test");
if(a.equals(b)) ===> true
String b="Test";
if(a.equals(b)) ===> true
String a="test";
String b=new String("test");
if(a.equals(b)) ===> true
So using .equals() method is recommended.
The == operator checks to see if the two strings are exactly the same object.
The .equals() method will check if the two strings have the same value.