File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes valueOf() vs parseXXX() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "valueOf() vs parseXXX()" Watch "valueOf() vs parseXXX()" New topic
Author

valueOf() vs parseXXX()

Chaitanya Jadhav
Ranch Hand

Joined: Mar 13, 2009
Posts: 41
According to K & B
The difference between the two methods is

* parseXxx() returns the named primitive.
* valueOf() returns a newly created wrapped object of the type that invoked
the method.

But both method return primitive as well as Object.??
then what is difference between them?




SCJP 1.5 80%
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

Chaitanya the book is right. valueOf returns a wrapper class object. This code



works only because of autoboxing. valueOf here returns an Integer object which is unboxed to int. To test this, try this code



Same is the case with parseInt here



SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Chaitanya Jadhav
Ranch Hand

Joined: Mar 13, 2009
Posts: 41
Ankit...

nice example .
thanks..
now i understood..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: valueOf() vs parseXXX()
 
Similar Threads
Doubt with String Methods
parseXXX vs valueOf In Primitive Type Wrapper Classes
parseXxx and valueOf
parseXxx() and valueOf()
difference between parsexxx() and valueOf()