File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes wrapper class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "wrapper class?" Watch "wrapper class?" New topic

wrapper class?

srikanth reddy
Ranch Hand

Joined: Jul 28, 2005
Posts: 252

here the Output iam getting is "b1.toString()" we have only one reference value ..what are we doing here by calling toString method...
can anyone help me???


[ September 28, 2005: Message edited by: Michael Ernest ]

Thanks & Regards<br /> <br />-Srikanth
Lalitha Gottumukkula
Ranch Hand

Joined: May 24, 2005
Posts: 45
I think if(b1.toString() == b1.toString()) is trying to compare two different String objects, not their values. b1.toString() returns a string equivalent of object b1.

Try to use if(b1.toString().equals(b1.toString()). This will compare values in the objects.
Michael Ernest
High Plains Drifter

Joined: Oct 25, 2000
Posts: 7292

Maybe this will help:


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
agrah upadhyay
Ranch Hand

Joined: Sep 01, 2005
Posts: 579

Here on calling b.toString() in b1.toString() == b1.toString() we get two different String object because call to toString() is
done at run == should result in false.Please correct me iff i am wrong
[ September 28, 2005: Message edited by: agrah upadhyay ]
agrah upadhyay
Ranch Hand

Joined: Sep 01, 2005
Posts: 579
Haa Haa Haa
With above posting i have completed my 101 posts
Arvind Giri
Ranch Hand

Joined: Jun 26, 2005
Posts: 91
yes! you are using only one reference b;
However keep in mind b.toString() returns a new String object, everytime it has been called.
That is why the actual checking here is between the reference returned by two b.toString(), which are different.

Regards<br /> <br />Arvind Giri<br />MCA,SCJP 1.4,SCWCD 1.4<br />Looking for SCDJWS
I agree. Here's the link:
subject: wrapper class?
It's not a secret anymore!