📜  Java的语言环境 hashCode() 方法及示例

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

Java的语言环境 hashCode() 方法及示例

JavaLocale 类hashCode()方法用于返回该语言环境的哈希码。

句法:

LOCALE.hashCode()

参数:该方法不带任何参数。

返回值:此方法返回给定语言环境的哈希码值。

下面的程序说明了 hashCode() 方法的工作:



方案一:

// Java code to illustrate hashCode() method
  
import java.util.*;
  
public class Locale_Demo {
    public static void main(String[] args)
    {
  
        // Creating a new locale
        Locale first_locale
            = new Locale("nu", "NO", "NY");
  
        // Displaying first locale
        System.out.println("First Locale: "
                           + first_locale);
  
        // Displaying the hash_code of this locale
        System.out.println("The Hash Code: "
                           + first_locale.hashCode());
    }
}
输出:
First Locale: nu_NO_NY
The Hash Code: 105152771

方案二:

// Java code to illustrate hashCode() method
import java.util.*;
  
public class Locale_Demo {
    public static void main(String[] args)
    {
  
        // Creating a new locale
        Locale first_locale
            = new Locale("ar", "SA");
  
        // Displaying first locale
        System.out.println("First Locale: "
                           + first_locale);
  
        // Displaying the hash_code of this locale
        System.out.println("The Hash Code: "
                           + first_locale.hashCode());
    }
}
输出:
First Locale: ar_SA
The Hash Code: 93059489