← 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?
- A.a == b
- B.a.equals(b)
- C.a.hashCode() == b
- 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 →