LearnFrenzy
Sign in Take a free test

Object Class and Wrapper Classes · Object and Wrapper Classes MCQ · Question 19

BigDecimal equals versus compareTo Answer, explanation & discussion

  • MCQ
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 19 Back to Exercise

Why does new BigDecimal("2.0").equals(new BigDecimal("2.00")) return false?

  • A A bug
  • B BigDecimal.equals compares both value and scale; use compareTo for numeric equality Correct
  • C Strings are compared
  • D They are different numbers
Correct Answer: Option B

compareTo returns 0 for them.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links