What are classes which `a.compareTo(b) == 0` does NOT mean that `a.equals(b) == true`?

I know that BigDecimal has that property, is there any other class like that?

Compares this BigDecimal with the specified Object for equality. Unlike compareTo, this method considers two BigDecimal objects equal only if they are equal in value and scale (thus 2.0 is not equal to 2.00 when compared by this method).

in other words, new BigDecimal("2.0").compareTo(new BigDecimal(2)) == 0 is true, but new BigDecimal("2.0").equals(new BigDecimal(2)) is false.

Go ahead and test this code:

submitted by /u/akerro

serverpoint hosting banner

You might also like More from author

Leave A Reply

Your email address will not be published.