File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt with == ( double equals ) method.

 
pradeep kumar rama
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to understand how the first output of the following piece of code returns "true"

As far as I know, the == operator compares two objects to determine if they are the same object in memory i.e. present in the same memory location. But here s1 and s5 point to different memory locations. Still how can the result be true ?

The Code I was refering to :



The result I got in the command prompt:

C:\Java Progs>javac EqualsTest.java

C:\Java Progs>java EqualsTest
== comparison : true
== comparison : true
Using equals method : true
false
Using equals method : true

C:\Java Progs>
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See our SCJP FAQ: Why do separate autoboxing conversions sometimes return the same reference?.
 
Joanne Neal
Rancher
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the What is the String pool? FAQ would be more useful here.
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12022
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String literals behave differently than the rest of the world.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic