I am new to Java. I read the following: do not use the == operators to determine if strings are equal. It only returns true if the strings are stored in the same location.
So..I opened Eclipse and tried the following with 2 ways of testing equality:
public class TestingStrings {
public static void main(String[] args) {
String x="I love Java";
String y="I love Java";
System.out.println(x.equals);
if(x==y){
System.out.println("Strings are equal");
}
else
System.out.println("Strings are not equal");
}
}
WHAT I GET IS:
true
Strings are equal
Why am I getting true? Should it be false, based on what I read?
So..I opened Eclipse and tried the following with 2 ways of testing equality:
public class TestingStrings {
public static void main(String[] args) {
String x="I love Java";
String y="I love Java";
System.out.println(x.equals);
if(x==y){
System.out.println("Strings are equal");
}
else
System.out.println("Strings are not equal");
}
}
WHAT I GET IS:
true
Strings are equal
Why am I getting true? Should it be false, based on what I read?