String Comparison Question
public class StringComparison{
public static void main(String args[]) {
String s1 = "abc";
String s2 = new String("abc");
s1.concat(s2);
if (s1 == s2) {
System.out.println("s1==s2: " + true);
} else {
System.out.println("s1==s2: " + false);
}
if (s1.equals(s2)) {
System.out.println("s1 equals s2: " + true);
} else {
System.out.println("s1 equals s2: " + false);
}
;
if (s1.equals(s2.concat("xyz"))) {
System.out.println("s1 equals with concat s2: " + true);
} else {
System.out.println("s1 equals with concat s2: " + false);
}
}
}
s1 equals s2 : true
s1 equals with concat s2 : false
post a comment