• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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.
 
A wop bop a lu bop a womp bam boom! Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic