• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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
 
Today's lesson is that you can't wear a jetpack AND a cape. I should have read this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic