• 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 classes: Sense of "valueOf" method?

 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
in the following code I present two ways of converting Strings to double primitives
Either by pareDouble or valueOf() in combination with wrapper class Double.
Why is it possible to omit „valueOf()“ method:
double d2 = Double.valueOf(args[0]).doubleValue();
equals:
double d4 = new Double(args[0]).doubleValue();
so why do we need „valueOf()“ method?

 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Double.valueOf() (and Double.copyValueOf()) methods are class (static) methods. So doing double trouble = Double.valueOf("2.71828"); is kinda convenient for
going from a String (or whatever valueOf() likes) to a primitive double variable.
-Barry
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's always more than one way to skin a cat.
 
reply
    Bookmark Topic Watch Topic
  • New Topic