Hi,
public class EqualsTest{
public static void main(
String[] args){
String s1 = "abc";
String s2 = s1;
String s5 = "abc";
String s3 = new String("abc");
String s4 = new String("abc");
System.out.println("== comparison : " +(s1 == s5));
System.out.println("== comparison : " +(s1 == s2));
System.out.println("Using equals method : " +s1.equals(s2));
System.out.println("== comparison : " +s3 == s4);
System.out.println("Using equals method : " +s3.equals(s4));
}
}
//output
== comparison : true
== comparison : true
Using equals method : true
false
Using equals method : true
Finished executing
public class EqualsTest{
public static void main(String[] args){
String s1 = "abc";
String s2 = s1;
String s5 = "abc";
String s3 = new String("abc");
String s4 = new String("abc");
//if we remove the brackets around "s1 == s5' it gives a different result.
System.out.println("== comparison : " +s1 == s5);
System.out.println("== comparison : " +(s1 == s2));
System.out.println("Using equals method : " +s1.equals(s2));
System.out.println("== comparison : " +s3 == s4);
System.out.println("Using equals method : " +s3.equals(s4));
}
}
//output
false
== comparison : true
Using equals method : true
false
Using equals method : true
Finished executing
in the above output why the s.o.p message is not printed and why it returns false?
Thanks
usha