🎙 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 5 of 10

What is the safest way to compare the values of two Integer variables a and b?

What is the safest way to compare the values of two Integer variables a and b?

  1. A.a == b
  2. B.a.equals(b)
  3. C.a.hashCode() == b
  4. D.(Object) a == (Object) b
Answer & explanation

Correct answer: a.equals(b)

equals compares the numbers. == compares object identity, which only works by luck for cached values.

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 →