Forums Register Login

string

+Pie Number of slices to send: Send
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));
}
}


the above program flashing the output like this:


== comparison : true
== comparison : true
Using equals method : true
false
Using equals method : true

can someone explain why the heck System.out.println(�== comparison : � + s3 == s4); is returning false.....

help would be very much appreaciated
regards
+Pie Number of slices to send: Send
hi madan...

when you are using new keyword then it is going to create different objects in heap.
+Pie Number of slices to send: Send
This question is discussed SO SO MANY TIMES.
Just search in the forum .
And here
Can you hear that? That's my theme music. I don't know where it comes from. Check under this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 748 times.
Similar Threads
String code
Doubt with == ( double equals ) method.
String question
(s1==s5) Vs s1==s5
== & equals()
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:28:26.