• 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

difference between parsexxx() and valueOf()

 
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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





Please if anyone can explain!!!


thanks in advance!!!
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 double (primitive type), and the second returns a Double (object, instance of the wrapper class Double).
 
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks All!!

Now i am clear with my doubt!!!


Preparing SCJP 1.5
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic