📜  Java中的 NumberFormat hashCode() 方法及示例

📅  最后修改于: 2022-05-13 01:55:37.663000             🧑  作者: Mango

Java中的 NumberFormat hashCode() 方法及示例

hashCode()方法是Java.text.NumberFormat的内置方法,它返回给定实例对象的哈希码值。

语法

public int hashCode()

参数:该函数不接受任何参数。

返回值:该函数返回哈希码值。

下面是上述函数的实现:

方案一:

// Java program to implement
// the above function
  
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Currency;
  
public class Main {
    public static void main(String[] args)
        throws Exception
    {
  
        // Get the instance for Locale US
        NumberFormat nF
            = NumberFormat
                  .getInstance(Locale.US);
  
        // Prints the hash-code value
        System.out.println("The hash-code values is: "
                           + nF.hashCode());
    }
}
输出:
The hash-code values is: 423132

方案二:

// Java program to implement
// the above function
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Currency;
public class Main {
    public static void main(String[] args)
        throws Exception
    {
  
        // Get the instance for Locale US
        NumberFormat nF
            = NumberFormat
                  .getInstance(Locale.US);
  
        // Prints the hash-code value
        System.out.println("The hash-code values is: "
                           + nF.hashCode());
    }
}
输出:
The hash-code values is: 423132

参考: https: Java/text/NumberFormat.html#hashCode()