wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "string" Watch "string" New topic
Author

string

Madan Mohan
Ranch Hand

Joined: Dec 05, 2008
Posts: 30
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
Ganeshkumar cheekati
Ranch Hand

Joined: Oct 13, 2008
Posts: 362
hi madan...

when you are using new keyword then it is going to create different objects in heap.


SCJP5 and SCWCD1.5
Think Twice Act Wise...
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

This question is discussed SO SO MANY TIMES.
Just search in the forum .
And here


SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
 
Don't get me started about those stupid light bulbs.
 
subject: string