BitSet hashCode() in Java

hashCode(): This method is available in java.util.BitSet class of Java.

Syntax:

int java.util.BitSet.hashCode()

This method returns the hash code value for this bit set. The hash code depends only on which bits are set within this BitSet.

Parameters: NA

Returns: the hash code value for this bit set.

Exceptions: NA

Approach

Java

import java.util.BitSet;

public class BitSethashCode {
    public static void main(String[] args) {
        BitSet bitSet = new BitSet(20);

        bitSet.set(1);

        bitSet.set(5);
        bitSet.set(6);
        bitSet.set(10);

        System.out.println(bitSet.hashCode());
    }
}

Output:

176


No comments:

Post a Comment