BigDecimal hashCode() Method in Java Last Updated : 04 Dec, 2018 Comments Improve Suggest changes Like Article Like Report 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). Syntax: 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. Examples: Input : BigDecimal = 67891 Output : Hashcode : 2104621 Input : BigDecimal = 67891.000 Output : Hashcode : 2104621003 Below programs illustrate the hashCode() function of BigDecimal class: Program 1: Java // Java program to demonstrate hashCode() method import java.io.*; import java.math.*; public class GFG { public static void main(String[] args) { // Creating a BigDecimal object BigDecimal b; // Assigning value b = new BigDecimal(4743); System.out.print("HashCode for " + b + " is "); System.out.println(b.hashCode()); } } Output: 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. Java // Java program to demonstrate hashCode() method import java.io.*; import java.math.*; public class GFG { public static void main(String[] args) { // Creating 2 BigDecimal objects BigDecimal b1, b2; // Assigning values b1 = new BigDecimal("4743"); b2 = new BigDecimal("4743.000"); int i1, i2; i1 = b1.hashCode(); i2 = b2.hashCode(); if (i1 == i2) { System.out.println("HashCodes of " + b1 + " and " + b2 + " are equal."); System.out.println("Both their HashCodes are " + i1 + "."); } else { System.out.println("HashCodes of " + b1 + " and " + b2 + " are not equal."); System.out.println("HashCodes of " + b1 + " is " + i1 + " and " + b2 + " is " + i2 + "."); } } } Output: HashCodes of 4743 and 4743.000 are not equal. HashCodes of 4743 is 147033 and 4743.000 is 147033003. Reference: https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html#hashCode() Comment More infoAdvertise with us Next Article Java AbstractMap hashCode() Method R RICHIK BHATTACHARJEE Follow Improve Article Tags : Misc Java Java-Functions java-math Java-BigDecimal Java-math-package +2 More Practice Tags : JavaMisc Similar Reads DecimalFormat hashCode() method in Java The hashCode() method is a built-in method of the java.text.DecimalFomrat class in Java and is used to get an integral hashCode value for this DecimalFormat instance. Syntax: public int hashCode() Parameters: The function does not accepts any parameter. Return Value: The function returns an integral 1 min read BigInteger hashCode() Method in Java The java.math.BigInteger.hashCode() method returns the hash code for this BigInteger. The hashcode is always the same if the object doesn't change. Hashcode is a unique code generated by the JVM at the time of object creation. We can use hashcode to perform some operation on hashing related algorith 2 min read BigInteger hashCode() Method in Java The java.math.BigInteger.hashCode() method returns the hash code for this BigInteger. The hashcode is always the same if the object doesn't change. Hashcode is a unique code generated by the JVM at the time of object creation. We can use hashcode to perform some operation on hashing related algorith 2 min read BigInteger hashCode() Method in Java The java.math.BigInteger.hashCode() method returns the hash code for this BigInteger. The hashcode is always the same if the object doesn't change. Hashcode is a unique code generated by the JVM at the time of object creation. We can use hashcode to perform some operation on hashing related algorith 2 min read Java AbstractMap hashCode() Method The hashCode() method of the AbstractMap class in Java is used to calculate a hash code value for a map. This hash code is based on the key-value mapping contained in the map. It ensures consistency such that two maps with the same entries have the same hash code.Example 1: Hash Code of a Non-Empty 2 min read Java AbstractMap hashCode() Method The hashCode() method of the AbstractMap class in Java is used to calculate a hash code value for a map. This hash code is based on the key-value mapping contained in the map. It ensures consistency such that two maps with the same entries have the same hash code.Example 1: Hash Code of a Non-Empty 2 min read Like