valueOf vs parseInt

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 :)

[719 byte] By [Xenobiusa] at [2007-11-27 8:52:32]
# 1
ignore my earlier post!! I posted without thinking. valueOf returns an Integer object, and parse int returns an int.Message was edited by: SomeoneElse
SomeoneElsea at 2007-7-12 21:08:12 > top of Java-index,Java Essentials,New To Java...
# 2

Thanks for your prompt reply. My concern is that I am currently reading a book to do the java certification SCJP, and both are included in the book. Meaning I will find them in the exam. My problem is that I can't quite understand what the book means on these 2 methods.

I don't expect you to know what the book wants to say withou seeing it hehe but if you can guide me to somwere were I could understand them better, I would appriciate.

Thanks once again

Xenobiusa at 2007-7-12 21:08:12 > top of Java-index,Java Essentials,New To Java...
# 3
AAA NOW this all makes sense!!!THANKS now I understand!!Thanks mate :)
Xenobiusa at 2007-7-12 21:08:12 > top of Java-index,Java Essentials,New To Java...