The clone() Method of Locale class in Java is used to simply create a clone or copy of an existing locale. The method copies the content of one locale to another.
Syntax:
Sec_Locale = First_Locale.clone()
Parameters: This method does not take any parameters.
Return Value: This method returns a clone of this locale.
Below programs illustrate the working of clone() method:
Program 1:
import java.util.*;
public class Locale_Demo {
public static void main(String[] args)
{
Locale first_locale
= new Locale( "no" , "NO" , "NY" );
Locale sec_locale;
System.out.println( "First Locale: "
+ first_locale);
sec_locale
= (Locale)first_locale.clone();
System.out.println( "Second Locale: "
+ sec_locale);
}
}
|
Output:
First Locale: no_NO_NY
Second Locale: no_NO_NY
Program 2:
import java.util.*;
public class Locale_Demo {
public static void main(String[] args)
{
Locale first_locale
= new Locale( "ga" , "IE" );
Locale sec_locale;
System.out.println( "First Locale: "
+ first_locale);
sec_locale
= (Locale)first_locale.clone();
System.out.println( "Second Locale: "
+ sec_locale);
}
}
|
Output:
First Locale: ga_IE
Second Locale: ga_IE