Saturday, October 25, 2025
HomeLanguagesJavaBigInteger hashCode() Method in Java

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 algorithms like hashtable, hashmap etc. We can search an object with that unique code.

Syntax:

public int hashCode()

Returns: The method returns an integer value which represents hashCode value for this BigInteger.

Examples:

Input: BigInteger1=32145
Output: 32145
Explanation: BigInteger1.hashCode()=32145.

Input: BigInteger1=7613721467324 
Output: -1255493552
Explanation: BigInteger1.hashCode()=-1255493552.

Example 1: Below programs illustrate hashCode() method of BigInteger class




// Java program to demonstrate 
// hashCode() method of BigInteger
  
import java.math.BigInteger;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Creating 2 BigInteger objects
        BigInteger b1, b2;
  
        b1 = new BigInteger("32145");
        b2 = new BigInteger("7613721467324");
  
        // apply hashCode() method
        int hashCodeOfb1 = b1.hashCode();
        int hashCodeOfb2 = b2.hashCode();
  
        // print hashCode
        System.out.println("hashCode of "
                           + b1 + " : " + hashCodeOfb1);
        System.out.println("hashCode of "
                           + b2 + " : " + hashCodeOfb2);
    }
}


Output:

hashCode of 32145 : 32145
hashCode of 7613721467324 : -1255493552

Example 2: When both bigInteger has same value




// Java program to demonstrate 
// hashCode() method of BigInteger
  
import java.math.BigInteger;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Creating 2 BigInteger objects
        BigInteger b1, b2;
  
        b1 = new BigInteger("4326516236135");
        b2 = new BigInteger("4326516236135");
  
        // apply hashCode() method
        int hashCodeOfb1 = b1.hashCode();
        int hashCodeOfb2 = b2.hashCode();
  
        // print hashCode
        System.out.println("hashCode of "
                           + b1 + " : " + hashCodeOfb1);
        System.out.println("hashCode of "
                           + b2 + " : " + hashCodeOfb2);
    }
}


Output:

hashCode of 4326516236135 : 1484200280
hashCode of 4326516236135 : 1484200280

Reference:
BigInteger hashCode() Docs

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS