java 方法 示例_Java语言环境getDisplayVariant()方法与示例
java 方法 示例
區域設置類getDisplayVariant()方法 (Locale Class getDisplayVariant() method)
Syntax:
句法:
public final String getDisplayVariant();public String getDisplayVariant(Locale lo);getDisplayVariant() method is available in java.util package.
getDisplayVariant()方法在java.util包中可用。
getDisplayVariant() method is used to display name for the locale variant and the displayed name will be localized as per based on the default locale.
getDisplayVariant()方法用于顯示語言環境變體的名稱,并且將根據默認語言環境對顯示的名稱進行本地化。
getDisplayVariant(Locale lo) method is used to display name for the locale variant and the displayed name will be localized as per based on the given locale (lo).
getDisplayVariant(Locale lo)方法用于顯示語言環境變體的名稱,并且顯示的名稱將根據給定的語言環境(lo)進行本地化。
These methods may throw an exception at the time of displaying a variant of the locale.
這些方法在顯示語言環境的變體時可能會引發異常。
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, getDisplayVariant() – It does not accept any parameter.
在第一種情況下, getDisplayVariant() –不接受任何參數。
In the second case, getDisplayVariant(Locale lo)
在第二種情況下, getDisplayVariant(Locale lo)
Locale lo – represents the locale.
語言環境lo –表示語言環境。
Return value:
返回值:
In both the cases, the return type of the method is String – it displays variant for the locale but does not return any value.
在這兩種情況下,方法的返回類型均為String -它顯示語言環境的變體,但不返回任何值。
Example:
例:
// Java program to demonstrate the example // of getDisplayVariant() method of Localeimport java.util.*;public class GetDisplayVariantOfLocale {public static void main(String[] args) {// Instantiates LocaleLocale lo1 = new Locale("JAPANESE", "JAPAN", "JAP");Locale lo2 = new Locale("FRENCH", "FRANCE", "FRA");// Display LocaleSystem.out.println("lo1: " + lo1);System.out.println("lo2: " + lo2);// By using getDisplayVariant() method is// to return the name for this locale variantString var1 = lo1.getDisplayVariant();System.out.println("lo1.getDisplayVariant(): " + var1);// By using getDisplayVariant(locale) method is// to return the name for this locale variant will// be localized by the given localeString var2 = lo1.getDisplayVariant(lo2);System.out.println("lo1.getDisplayVariant(lo2): " + var2);} }Output
輸出量
lo1: japanese_JAPAN_JAP lo2: french_FRANCE_FRA lo1.getDisplayVariant(): JAP lo1.getDisplayVariant(lo2): JAP翻譯自: https://www.includehelp.com/java/locale-getdisplayvariant-method-with-example.aspx
java 方法 示例
總結
以上是生活随笔為你收集整理的java 方法 示例_Java语言环境getDisplayVariant()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用OpenCV在Python中进行人脸
- 下一篇: Java ObjectInputStre