Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
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
Forum:
Programmer Certification (OCPJP)
difference between parsexxx() and valueOf()
dhwani mathur
Ranch Hand
Posts: 621
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hi All
i have a doubt from K&B Book Chapter 3
i want to know what actualy is the difference between
parsing and getting value or just directly getting the value
it is mentioned in the book as
parseXxx() returns the named primitive. valueOf() returns a newly created wrapped object of the type that invoked the method. Here are some examples of these methods in action: double d4 = Double.parseDouble("3.14"); // convert a String // to a primitive System.out.println("d4 = " + d4); // result is d4 = 3.14 Double d5 = Double.valueOf("3.14"); // create a Double obj [B]//here if i try to print d5 what will be value ? // if it will be 3.14 than what the difference[/B]
Please if anyone can explain!!!
thanks in advance!!!
Jesper de Jong
Java Cowboy
Posts: 16084
88
I like...
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Read the lines from the book carefully:
parseXxx() returns the named
primitive
.
valueOf() returns a newly created
wrapped object
of the type that invoked the method.
Note that the first returns a
d
ouble (primitive type), and the second returns a
D
ouble (object, instance of the wrapper class Double).
Jesper's Blog
-
Pluralsight Author Page
Bob Ruth
Ranch Hand
Posts: 320
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Yes, make sure that you understand the difference between a primitive numeric variable and the wrapper class of the associated type:
int - Integer
long - Long
byte - Byte
and so on....
Be sure to take a look at autoboxing, if you are studying 1.5...
then, your question will answer itself....
------------------------
Bob
SCJP - 86% - June 11, 2009
jone wiilum
Ranch Hand
Posts: 49
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
parseXxx() returns the named primitive.
valueOf() returns a newly created wrapped object
And parseXxx() take
string
and then convert into a primitive .
eg.
int i=Integer.parseInt(args[0]);
dhwani mathur
Ranch Hand
Posts: 621
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks All!!
Now i am clear with my doubt!!!
Preparing
SCJP
1.5
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
parseXxx and valueOf
valueOf() vs parseXXX()
Problem with the Wrapper Conversion
parseXxx() and valueOf()
instanceOf()
More...