Home » Java programming language

Java BitSet hashCode() Method with Example

BitSet Class hashCode() method: Here, we are going to learn about the hashCode() method of BitSet Class with its syntax and example.
Submitted by Preeti Jain, on January 21, 2020

BitSet Class hashCode() method

  • hashCode() method is available in java.util package.
  • hashCode() method is used to retrieve hash code for this bit set (BitSet).
  • hashCode() method is a non-static method, so it is accessible with the class object 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 retrieving hash code.

Syntax:

    public int hashCode();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is int, it returns hash code value for this BitSet.

Example:

// Java program to demonstrate the example 
// of int hashCode() method of BitSet.

import java.util.*;

public class HashCodeOfBitSet {
    public static void main(String[] args) {
        // create an object of BitSet
        BitSet bs = new BitSet(10);

        // By using set() method is to set
        // the values in BitSet 
        bs.set(10);
        bs.set(20);
        bs.set(30);
        bs.set(40);
        bs.set(50);

        // Display Bitset
        System.out.println("bs: " + bs);

        // By using hashCode() method is to return
        // the hash code of this BitSet
        int hc = bs.hashCode();

        // Display hash code of bs
        System.out.println("bs.hashCode(): " + hc);
    }
}

Output

bs: {10, 20, 30, 40, 50}
bs.hashCode(): 1075053010


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.