Java Utility Library

Java BitSet - hashCode() Method



The java.util.BitSet.hashCode() method returns the hash code value for this BitSet. The hash code depends only on which bits are set within this BitSet.

Syntax

public int hashCode()

Parameters

No parameter is required.

Return Value

Returns the hash code value for this BitSet.

Exception

NA.

Example:

In the example below, the java.util.BitSet.hashCode() method returns the hash code value for the given BitSet.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {   
    //creating a BitSet
    BitSet BSet = new BitSet();

    //populating BitSet
    BSet.set(10);
    BSet.set(20);
    BSet.set(30);
    BSet.set(40);
    BSet.set(50);

    //print hashcode of the BitSet
    System.out.print("Hash Code of BSet is: ");
    System.out.print(BSet.hashCode());
  }
}

The output of the above code will be:

Hash Code of BSet is: 1075053010

❮ Java.util - BitSet