File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

string

 
Madan Mohan
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 362
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi madan...

when you are using new keyword then it is going to create different objects in heap.
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question is discussed SO SO MANY TIMES.
Just search in the forum .
And here
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic