Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Wrapper Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Wrapper " Watch "Wrapper " New topic
Author

Wrapper

Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 477
String s="23.3";
int i=(int)(Double.valueOf(s).doubleValue());

Double.valueOf(s) gives result as Wrapper object.then how come "Double.doubleValue()" is working.Please help.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Originally posted by Shiva Mohan:
String s="23.3";
int i=(int)(Double.valueOf(s).doubleValue());

Double.valueOf(s) gives result as Wrapper object.then how come "Double.doubleValue()" is working.Please help.


Double.valueOf(s) does give a reference to a Double object. Then you extract the double value in the wrapper with doubleValue().
Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 477
Thanks Keith.One more question on wrapper.

Boolean d=Boolean.valueOf("23.5");

when will the Boolean.valueOf(String /boolean) will give NumberFormatException.Could you please give one example.i have tried many options which didn't throw that exception.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
It's not going to throw a NumberFormatException because of the way that Boolean.valueOf(String) works.

If the String is equal, ignoring case, to "true", then the boolean value stored in the wrapper will be true.

Any other String or null will cause the boolean value stored in the wrapper to be false.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wrapper
 
Similar Threads
format double
Valueof
Just a weird doubt
null value in wrapper
hashcode