🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Java Data Types: all 10 questions

Quiz: Java Data Types · Question 5 of 10

Which converts the String "42" into an int?

Which converts the String "42" into an int?

  1. A.(int) "42"
  2. B.Integer.parseInt("42")
  3. C.String.toInt("42")
  4. D.int.parse("42")
Answer & explanation

Correct answer: Integer.parseInt("42")

Integer.parseInt parses text into an int. You cannot cast a String to int.

Can you get the rest right without peeking?

Take the timed Quiz: Java Data Types quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →