Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

valueOf vs parseInt

807600Jun 26 2007 — edited Jun 26 2007
Hello all,

I was experimenting with wrapper classes and their methods.
String s = "15";
		
System.out.println(Integer.valueOf(s + 1)); //answer 16	
System.out.println(Integer.parseInt(s) + 1); //answer 16
As you can see above, by running the code above, valueOf generated 16 and so did parseInt. The reason I added 1 to the answer is to know if it is really converting the string 15 to an integer because if it didn't, I would get 151 and not 16.

My question is this, whats the difference? I know that valueOf can convert an integer to a binary number but im not so sure.

Thanks all :)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 24 2007
Added on Jun 26 2007
3 comments
179 views