🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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")?

  1. A.parseInt returns a String, valueOf returns an int
  2. B.parseInt returns a primitive int; valueOf returns an Integer object
  3. C.Only valueOf can throw NumberFormatException
  4. 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 →