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

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

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

Java.text.ChoiceFormat类的hashCode()方法用于获取选择格式对象的哈希码。此哈希码值以整数形式返回。

句法:

public int hashCode()

参数:此方法不接受任何参数。

返回值:此方法以整数形式返回选择格式对象的哈希码

以下是说明hashCode()方法的示例:

示例 1:

// Java program to demonstrate hashCode() method
  
import java.text.*;
import java.util.*;
import java.io.*;
  
public class GFG {
    public static void main(String[] argv)
    {
        // creating and initializing ChoiceFormat
        ChoiceFormat cf
            = new ChoiceFormat(
                "4#wed| 5#thu | 6#fri | 7#sat");
  
        // getting hashcode of  ChoiceFormat object
        // using hashCode() method
        int hash = cf.hashCode();
  
        // display the result
        System.out.print("hashCode :- " + hash);
    }
}
输出:
hashCode :- 113634 

示例 2:

// Java program to demonstrate hashCode() method
  
import java.text.*;
import java.util.*;
import java.io.*;
  
public class GFG {
    public static void main(String[] argv)
    {
        // creating and initializing limit
        double[] limit = { 1, 2, 3, 4 };
  
        // creating and initializing format
        String[] format
            = { "add", "sub", "multiply", "divide" };
  
        // creating and initializing ChoiceFormat
        ChoiceFormat cf
            = new ChoiceFormat(limit, format);
  
        // getting hashcode of  ChoiceFormat object
        // using hashCode() method
        int hash = cf.hashCode();
  
        // display the result
        System.out.print("hashCode :- " + hash);
    }
}
输出:
hashCode :- -1331463043

参考: https://docs.oracle.com/javase/9/docs/api/ Java/text/ChoiceFormat.html#hashCode–