Why can't we add BigDecimal to TreeSet?

I read somewhere that we cannot add BigDecimal to TreeSet because it does not correctly implement compareTo method, for example. for 9.0 and 9.00 it will return 0, although using the equals method it will return false. This seems to be the reason. Can someone explain in a little more detail?


source to share

1 answer


in this case will return false because their precision is different. compareTo()

will return 0 because the "value" will be the same.



All Articles