当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java Locale clone()用法及代码示例


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


相关用法


注:本文由纯净天空筛选整理自Chinmoy Lenka大神的英文原创作品 Locale clone() Method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。