當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java Java.util.Locale.getCountry()用法及代碼示例


描述

這個java.util.Locale.getCountry()方法返回此語言環境的國家/地區代碼,它可以是空字符串或大寫的 ISO 3166 2 字母代碼。

聲明

以下是聲明java.util.Locale.getCountry()方法

public String getCountry()

參數

NA

返回值

此方法不返回值。

異常

NA

示例

下麵的例子展示了 java.util.Locale.getCountry() 方法的用法。

package com.tutorialspoint;

import java.util.*;

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

      // create a new locale
      Locale locale = new Locale("ENGLISH", "US");

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

      // print the country of this locale
      System.out.println("Country:" + locale.getCountry());
   }
}

讓我們編譯並運行上麵的程序,這將產生以下結果——

Locale1:english_US
Country:US

相關用法


注:本文由純淨天空篩選整理自 Java.util.Locale.getCountry() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。