The java.math.BigDecimal.hashCode() returns the hash code for this BigDecimal. The hashcode will generally not be the same for two BigDecimal objects with equal values and different scale (like 4743.0 and 4743.00).
public int hashCode()
Parameters: This method does not accept any parameters.
Return Values: This method returns an integer value which is equal to the hashCode Value of the BigDecimal Object.
Input : BigDecimal = 67891 Output : Hashcode : 2104621 Input : BigDecimal = 67891.000 Output : Hashcode : 2104621003
Below programs illustrate the hashCode() function of BigDecimal class:
HashCode for 4743 is 147033
Program 2: This program will illustrate that hashcode for two different BigDecimals with equal value but different scale will be different.
HashCodes of 4743 and 4743.000 are not equal. HashCodes of 4743 is 147033 and 4743.000 is 147033003.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.