So I was taught that “==” only checks whether they are the same object and “equals()” checks the values of the objects.
But for Strings, I found that “==” also checks for values. For example:-
String x = "apple";
String y = "orange";
x=y;
if (x==y){
System.out.println("yes");
}else{
System.out.println("no");
}
//OUTPUT: yes
or
String x = "apple";
String y = "apple";
y = "watermelon";
if (x==y){
System.out.println("yes");
}else{
System.out.println("no");
}tem.out.println("no");
//OUTPUT: no