📜  Java中的 MinguoDate hashCode() 方法与示例

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

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

Java.time.chrono.MinguoDate类的hashCode()方法用于获取特定 Minguo 日期的哈希码。

句法:

public int hashCode()

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

返回值:此方法返回特定民国日期的哈希码。

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

Java
// Java program to demonstrate
// hashCode() method
  
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.temporal.*;
  
public class GFG {
    public static void main(String[] argv)
    {
        try {
            // creating and initializing
            // MinguoDate Object
            MinguoDate hidate = MinguoDate.now();
  
            // getting hash code of the date
            // by using hashCode() method
            long tempo = hidate.hashCode();
  
            // display the result
            System.out.println("hashcode : "
                               + tempo);
        }
        catch (DateTimeException e) {
            System.out.println("passed parameter can"
                               + " not form a date");
            System.out.println("Exception thrown: "
                               + e);
        }
    }
}


Java
// Java program to demonstrate
// hashCode() method
  
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.temporal.*;
  
public class GFG {
    public static void main(String[] argv)
    {
        try {
            // creating and initializing
            // MinguoDate Object
            MinguoDate hidate = MinguoDate.of(1345, 06, 13);
  
            // getting hash code of the date
            // by using hashCode() method
            long tempo = hidate.hashCode();
  
            // display the result
            System.out.println("hashcode : "
                               + tempo);
        }
        catch (DateTimeException e) {
            System.out.println("passed parameter can"
                               + " not form a date");
            System.out.println("Exception thrown: "
                               + e);
        }
    }
}


输出:
hashcode : -1990230825

示例 2:

Java

// Java program to demonstrate
// hashCode() method
  
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.temporal.*;
  
public class GFG {
    public static void main(String[] argv)
    {
        try {
            // creating and initializing
            // MinguoDate Object
            MinguoDate hidate = MinguoDate.of(1345, 06, 13);
  
            // getting hash code of the date
            // by using hashCode() method
            long tempo = hidate.hashCode();
  
            // display the result
            System.out.println("hashcode : "
                               + tempo);
        }
        catch (DateTimeException e) {
            System.out.println("passed parameter can"
                               + " not form a date");
            System.out.println("Exception thrown: "
                               + e);
        }
    }
}
输出:
hashcode : -1996123070

参考: https://docs.oracle.com/javase/9/docs/api/ Java/time/chrono/MinguoDate.html#hashCode–