Java Locale hashCode() 方法



描述

java Locale hashCode() 方法返回此區域設定的雜湊碼。

宣告

以下是 java.util.Locale.hashCode() 方法的宣告

public int hashCode()

引數

返回值

此方法返回此物件的雜湊碼值。

異常

獲取 US 區域設定的雜湊碼示例

以下示例演示了 Java Locale hashCode() 方法的用法。我們建立了一個 US 的區域設定,然後檢索並列印其雜湊碼。

package com.tutorialspoint;

import java.util.Locale;

public class LocaleDemo {
   public static void main(String[] args) {

      // create a new locale
      Locale locale = Locale.US;

      // print this locale
      System.out.println("Locale:" + locale);

      // print the hashcode of this locale
      System.out.println("HashCode:" + locale.hashCode());
   }
}

輸出

讓我們編譯並執行以上程式,這將產生以下結果:

Locale:en_US
HashCode:96636889

獲取加拿大區域設定的雜湊碼示例

以下示例演示了 Java Locale hashCode() 方法的用法。我們建立了一個加拿大的區域設定,然後檢索並列印其雜湊碼。

package com.tutorialspoint;

import java.util.Locale;

public class LocaleDemo {
   public static void main(String[] args) {

      // create a new locale
      Locale locale = Locale.CANADA;

      // print this locale
      System.out.println("Locale:" + locale);

      // print the hashcode of this locale
      System.out.println("HashCode:" + locale.hashCode());
   }
}

輸出

讓我們編譯並執行以上程式,這將產生以下結果:

Locale:en_CA
HashCode:96619033

獲取法國區域設定的雜湊碼示例

以下示例演示了 Java Locale hashCode() 方法的用法。我們建立了一個法國的區域設定,然後檢索並列印其雜湊碼。

package com.tutorialspoint;

import java.util.Locale;

public class LocaleDemo {
   public static void main(String[] args) {

      // create a new locale
      Locale locale = Locale.FRANCE;

      // print this locale
      System.out.println("Locale:" + locale);

      // print the hashcode of this locale
      System.out.println("HashCode:" + locale.hashCode());
   }
}

輸出

讓我們編譯並執行以上程式,這將產生以下結果:

Locale:fr_FR
HashCode:97665128
java_util_locale.htm
廣告