Home »
Java »
Java Reference »
Java MathContext Class
Java MathContext Class | hashCode() Method with Example
MathContext Class hashCode() method: Here, we are going to learn about the hashCode() method of MathContext Class with its syntax and example.
Submitted by Preeti Jain, on May 12, 2020
MathContext Class hashCode() method
- hashCode() method is available in java.math package.
- hashCode() method is used to get the hash code value of this MathContext.
- hashCode() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
- hashCode() method does not throw an exception at the time of returning hash code.
Syntax:
public int hashCode();
Parameter(s):
Return value:
The return type of this method is int, it retrieves this MathContext hash code value.
Example:
// Java program to demonstrate the example
// of int hashCode() method of MathContext
import java.math.*;
public class HashCodeOfMC {
public static void main(String args[]) {
// Initialize three MathContext objects
MathContext ma_co1 = new MathContext(3, RoundingMode.CEILING);
MathContext ma_co2 = new MathContext(4);
MathContext ma_co3 = new MathContext(6, RoundingMode.FLOOR);
// returns the hash code of this MathContext
// ma_co1
int hash_code = ma_co1.hashCode();
System.out.println("ma_co1.hashCode(): " + hash_code);
// returns the hash code of this MathContext
// ma_co2
hash_code = ma_co2.hashCode();
System.out.println("ma_co2.hashCode(): " + hash_code);
// returns the hash code of this MathContext
// ma_co3
hash_code = ma_co3.hashCode();
System.out.println("ma_co3.hashCode(): " + hash_code);
}
}
Output
ma_co1.hashCode(): 1420167577
ma_co2.hashCode(): 931231881
ma_co3.hashCode(): -18805464