Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in valueOf Arg

 
vishal mishra
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Namaste Friends !!

Please explain me why

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


Thanks.
 
Paul Clapham
Sheriff
Posts: 21314
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
vishal mishra
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You all for clearing my doubts
 
Henry Wong
author
Marshal
Pie
Posts: 21385
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
vishal mishra
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic