當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java BitSet hashCode()用法及代碼示例

BitSet類hashCode()方法

  • hashCode() 方法在 java.util 包中可用。
  • hashCode() 方法用於檢索此位集 (BitSet) 的哈希碼。
  • hashCode() 方法是一個非靜態方法,因此可以通過類對象訪問它,如果我們嘗試使用類名訪問該方法,則會出現錯誤。
  • hashCode() 方法在檢索哈希碼時不會拋出異常。

用法:

    public int hashCode();

參數:

  • 它不接受任何參數。

返回值:

這個方法的返回類型是int,它返回此 BitSet 的哈希碼值。

例:

// 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);
    }
}

輸出

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


相關用法


注:本文由純淨天空篩選整理自Preeti Jain大神的英文原創作品 Java BitSet hashCode() Method with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。