== compares the exact values. So it compares if the primitive values are the same, or if the references (addresses) are the same. That’s why == often doesn’t work on Strings ; Strings are objects, and doing == on two string variables just compares if the address is same in memory, as others have pointed out. .
Read moreHow do I make one string equal another in Java?
Using String. equals() :In Java, string equals() method compares the two given strings based on the data/content of the string. If all the contents of both the strings are same then it returns true. If any character does not match, then it returns false.29 Mar 2020
Read more