• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Wrapper classes: Sense of "valueOf" method?

 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
There's always more than one way to skin a cat.
 
You save more money with a clothesline than dozens of light bulb purchases. Tiny ad:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!