← Quiz: Wrapper Classes and Autoboxing: all 10 questions
Quiz: Wrapper Classes and Autoboxing · Question 8 of 10
What is the difference between Integer.parseInt("7") and Integer.valueOf("7")?
What is the difference between Integer.parseInt("7") and Integer.valueOf("7")?
- A.parseInt returns a String, valueOf returns an int
- B.parseInt returns a primitive int; valueOf returns an Integer object
- C.Only valueOf can throw NumberFormatException
- D.They return exactly the same type
Answer & explanation
Correct answer: parseInt returns a primitive int; valueOf returns an Integer object
Both parse the text; parseInt gives an int and valueOf gives a (possibly cached) Integer.
Can you get the rest right without peeking?
Take the timed Quiz: Wrapper Classes and Autoboxing quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →