📌  相关文章
📜  Java中的 MessageFormat hashCode() 方法与示例

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

Java中的 MessageFormat hashCode() 方法与示例

Java.text.MessageFormat类的hashCode()方法用于获取此消息格式对象的哈希码。
句法:

public int hashCode()

参数:此方法不接受任何参数作为参数。
返回值:此方法返回此消息格式对象的哈希码。
以下是说明hashCode()方法的示例:
示例 1:

Java
// 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  MessageFormat
        MessageFormat mf
            = new MessageFormat("{0, number, #}, {2, date, #.#}, {4, time}");
 
        // getting hash code
        // for this MessageFormat Object
        // using hashCode() method
        int hash = mf.hashCode();
 
        // display the result
        System.out.println("Hashcode is : " + hash);
    }
}


Java
// 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  MessageFormat
        MessageFormat mf
            = new MessageFormat("{0, number, #}, {4, time}");
 
        // getting hash code
        // for this MessageFormat Object
        // using hashCode() method
        int hash = mf.hashCode();
 
        // display the result
        System.out.println("Hashcode is : " + hash);
    }
}


输出:
Hashcode is : 1408

示例 2:

Java

// 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  MessageFormat
        MessageFormat mf
            = new MessageFormat("{0, number, #}, {4, time}");
 
        // getting hash code
        // for this MessageFormat Object
        // using hashCode() method
        int hash = mf.hashCode();
 
        // display the result
        System.out.println("Hashcode is : " + hash);
    }
}
输出:
Hashcode is : 44

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