Java中的Locale類的clone()方法用於簡單地創建現有語言環境的克隆或副本。該方法將一個語言環境的內容複製到另一個語言環境。
用法:
Sec_Locale = First_Locale.clone()
參數:此方法不帶任何參數。
返回值:此方法返回此語言環境的副本。
以下示例程序旨在說明clone()方法的用法:
示例1:
// Java code to illustrate clone() method
import java.util.*;
public class Locale_Demo {
public static void main(String[] args)
{
// Creating a new locale
Locale first_locale
= new Locale("no", "NO", "NY");
// Creating a second locale
Locale sec_locale;
// Displaying first locale
System.out.println("First Locale: "
+ first_locale);
// Cloning first locale to second
sec_locale
= (Locale)first_locale.clone();
// Displaying second locale
System.out.println("Second Locale: "
+ sec_locale);
}
}
輸出:
First Locale: no_NO_NY Second Locale: no_NO_NY
示例2:
// Java code to illustrate clone() method
import java.util.*;
public class Locale_Demo {
public static void main(String[] args)
{
// Creating a new locale
Locale first_locale
= new Locale("ga", "IE");
// Creating a second locale
Locale sec_locale;
// Displaying first locale
System.out.println("First Locale: "
+ first_locale);
// Cloning first locale to second
sec_locale
= (Locale)first_locale.clone();
// Displaying second locale
System.out.println("Second Locale: "
+ sec_locale);
}
}
輸出:
First Locale: ga_IE Second Locale: ga_IE
相關用法
- Java TimeZone getDisplayName(Locale locale)用法及代碼示例
- Java Locale.Builder setLocale(Locale)用法及代碼示例
- Java Locale getDisplayVariant(Locale inLoc)用法及代碼示例
- Java Locale getDisplayName(Locale)用法及代碼示例
- Java Locale getDisplayLanguage(Locale)用法及代碼示例
- Java Locale getDisplayCountry(Locale)用法及代碼示例
- Java Locale hashCode()用法及代碼示例
- Java Locale getISO3Language()用法及代碼示例
- Java Locale getDisplayVariant()用法及代碼示例
- Java Locale toLanguageTag()用法及代碼示例
- Java Locale getLanguage()用法及代碼示例
- Java Locale getCountry()用法及代碼示例
- Java Locale toString()用法及代碼示例
- Java Locale getVariant()用法及代碼示例
注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 Locale clone() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。