• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Wrapper

 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic