java 方法 示例_Java语言环境getDisplayCountry()方法与示例

java 方法 示例

区域设置类getDisplayCountry()方法 (Locale Class getDisplayCountry() method)

Syntax:

句法:

    public final String getDisplayCountry();
    public String getDisplayCountry(Locale lo);

  • getDisplayCountry() method is available in java.util package.

    getDisplayCountry()方法在java.util包中可用。

  • getDisplayCountry() method is used to display the country name for this Locale.

    getDisplayCountry()方法用于显示此语言环境的国家/地区名称。

  • getDisplayCountry(Locale lo) method is used to display the country name for the locale and the displayed name will be localized as per based on the given parameter (lo) when possible.

    getDisplayCountry(Locale lo)方法用于显示语言环境的国家/地区名称,并且在可能的情况下,将根据给定的参数(lo)根据显示的名称进行本地化。

  • These methods may throw an exception at the time of displaying the name of the country.

    这些方法在显示国家/地区名称时可能会引发异常。

    NullPointerException: This exception may throw when the given parameter is null exists.

    NullPointerException :当给定参数为null时,可能引发此异常。

  • These are non-static methods and it is accessible with the class object and if we try to access these methods with the class name then also we will get an error.

    这些是非静态方法,可通过类对象访问,如果尝试使用类名访问这些方法,则也会收到错误消息。

Parameter(s):

参数:

  • In the first case, getDisplayCountry() – It does not accept any parameter.

    在第一种情况下, getDisplayCountry() –它不接受任何参数。

  • In the second case, getDisplayCountry(Locale lo)

    在第二种情况下, getDisplayCountry(Locale lo)

    Locale lo – represents the locale whose localized behavior depends on the displayed name.

    语言环境lo –表示语言环境的本地化行为取决于显示的名称。

Return value:

返回值:

In both the cases, the return type of the method is String,

在这两种情况下,方法的返回类型均为String 。

  • In the first case, it displays the country name for this locale.

    在第一种情况下,它显示此语言环境的国家/地区名称。

  • In the second case, it displays the country name for the locale based on the given parameter.

    在第二种情况下,它将根据给定的参数显示语言环境的国家/地区名称。

Example:

例:

// Java program to demonstrate the example 
// of getDisplayCountry() method of Locale

import java.util.*;

public class GetDisplayCountryOfLocale {
    public static void main(String[] args) {
        // Instantiates Locale
        Locale lo1 = Locale.getDefault();
        Locale lo2 = new Locale("JAPANESE", "JAPAN");

        // Display Locale
        System.out.println("lo1: " + lo1);
        System.out.println("lo2: " + lo2);

        // By using getDisplayCountry() method is
        // to return the country name this locale
        String co1 = lo1.getDisplayCountry();
        System.out.println("lo1.getDisplayCountry(): " + co1);

        // By using getDisplayCountry(locale) method is
        // to return the country name this locale will
        // be localized by the given locale
        String co2 = lo1.getDisplayCountry(lo2);
        System.out.println("lo1.getDisplayCountry(lo2): " + co2);

    }
}

Output

输出量

lo1: en_US
lo2: japanese_JAPAN
lo1.getDisplayCountry(): United States
lo1.getDisplayCountry(lo2): United States


翻译自: https://www.includehelp.com/java/locale-getdisplaycountry-method-with-example.aspx

java 方法 示例

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值