This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Wrapper classes: Sense of Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Wrapper classes: Sense of "valueOf" method?" Watch "Wrapper classes: Sense of "valueOf" method?" New topic
Author

Wrapper classes: Sense of "valueOf" method?

Thomas Markl
Ranch Hand

Joined: Mar 08, 2001
Posts: 192
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?

Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
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


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
There's always more than one way to skin a cat.


Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wrapper classes: Sense of "valueOf" method?