• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Wrapper

 
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic