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 Doubt in valueOf Arg Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in valueOf Arg" Watch "Doubt in valueOf Arg" New topic
Author

Doubt in valueOf Arg

vishal mishra
Ranch Hand

Joined: Jul 12, 2010
Posts: 103
Namaste Friends !!

Please explain me why

compiles as it takes String as an argument not an integer ??


Thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

Well, yes, there is an Integer.valueOf(String) method, and what you posted isn't an example of it. But there is also an Integer.valueOf(int) method, and what you posted IS a valid and compilable example of it.
vishal mishra
Ranch Hand

Joined: Jul 12, 2010
Posts: 103
Paul Clapham wrote:Well, yes, there is an Integer.valueOf(String) method, and what you posted isn't an example of it. But there is also an Integer.valueOf(int) method, and what you posted IS a valid and compilable example of it.


Thanks for replying....and I agree that there is a method Integer.valueOf(int) but it rises another question in my mind(this not a doubt but still a question) why the method that takes integer as an argument is not listed in following docs..
http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Integer.html

am i missing something or misunderstood the functioning of valueOf method ??

Please tell me...
Stuart A. Burkett
Ranch Hand

Joined: May 30, 2012
Posts: 679
vishal mishra wrote:why the method that takes integer as an argument is not listed in following docs..
http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Integer.html

Because it was added in Java 1.5.
If you look at the latest Javadoc you can see the Since setting at the bottom - this indicates the version of java it was added.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

vishal mishra wrote:Namaste Friends !!

Please explain me why

compiles as it takes String as an argument not an integer ??


Thanks.


The method is used to convert the input parameter into an integer when possible and the method taking a String parameter exists like others have pointed out. The return value may also be sourced from a pool of Integers, depending on whether it lies in the range -128 -> 127 (or a configured value).


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
vishal mishra
Ranch Hand

Joined: Jul 12, 2010
Posts: 103
Thank You all for clearing my doubts
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19064
    
  40

vishal mishra wrote:Thank You all for clearing my doubts



It is also highly recommended that you use the correct documentation (for the version of Java that you are using) from now on.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
vishal mishra
Ranch Hand

Joined: Jul 12, 2010
Posts: 103
Henry Wong wrote:
vishal mishra wrote:Thank You all for clearing my doubts



It is also highly recommended that you use the correct documentation (for the version of Java that you are using) from now on.

Henry


Always, that is why i asked what am i missing.. i have missed to check the docs version, so, thank you again for correcting me...thanks !!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in valueOf Arg