Java.math.MathContext.hashCode() 方法



說明

java.math.MathContext.hashCode() 返回此 MathContext 的雜湊編碼。

宣告

以下是 java.math.MathContext.hashCode() 方法的宣告。

public int hashCode()

覆蓋

Object 類中的 hashCode。

引數

不適用

返回值

此方法返回此 MathContext 的雜湊編碼。

例外

不適用

示例

以下示例展示了 math.MathContext.hashCode() 方法的用法。

package com.tutorialspoint;

import java.math.*;

public class MathContextDemo {

   public static void main(String[] args) {

      // create 2 MathContext objects
      MathContext mc1, mc2;

      // assign context settings to mc1, mc2
      mc1 = new MathContext(5);
      mc2 = new MathContext(20, RoundingMode.UNNECESSARY);

      // create 2 int objects
      int i1, i2;

      // assign hashcode of mc1, mc2 to i1, i2
      i1 = mc1.hashCode();
      i2 = mc2.hashCode();

      String str1 = "Hashcode of mc1 is " + i1;
      String str2 = "Hashcode of mc2 is " + i2;

      // print i1, i2 values
      System.out.println( str1 );
      System.out.println( str2 );
   }
}

讓我們編譯並執行上述程式,這將生成以下結果 -

Hashcode of mc1 is 1802290004
Hashcode of mc2 is -1299934805
java_math_mathcontext.htm
廣告
© . All rights reserved.