Java中的Locale類的toString()方法用於返回此語言環境的字符串表示形式。每個元素(即語言,國家或地區的變體)之間都用下劃線隔開
用法:
LOCALE.toString()
參數:此方法不帶任何參數。
返回值:此方法返回此語言環境的字符串表示形式。
以下示例程序旨在說明toString()方法的用法:
示例1:
// Java code to illustrate toString() 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 string of this locale
System.out.println("The String: "
+ first_locale.toString());
}
}
輸出:
First Locale: nu_NO_NY The String: nu_NO_NY
示例2:
// Java code to illustrate toString() 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 string of this locale
System.out.println("The String: "
+ first_locale.toString());
}
}
輸出:
First Locale: ar_SA The String: ar_SA
相關用法
- Java Locale getDisplayVariant(Locale inLoc)用法及代碼示例
- Java TimeZone getDisplayName(Locale locale)用法及代碼示例
- Java Locale.Builder setLocale(Locale)用法及代碼示例
- Java Locale getDisplayCountry(Locale)用法及代碼示例
- Java Locale getDisplayName(Locale)用法及代碼示例
- Java Locale getDisplayLanguage(Locale)用法及代碼示例
- Java Locale getCountry()用法及代碼示例
- Java Formatter locale()用法及代碼示例
- Java Locale setDefault()用法及代碼示例
- Java Locale getAvailableLocales()用法及代碼示例
- Java Locale getISOLanguages()用法及代碼示例
- Java Locale getISOCountries()用法及代碼示例
- Java Locale getLanguage()用法及代碼示例
- Java Locale clone()用法及代碼示例
注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 Locale toString() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。