Java Locale clone() Method
Description
The Java Locale clone() method creates a copy of this locale.
Declaration
Following is the declaration for java.util.Locale.clone() method
public Object clone()
Parameters
NA
Return Value
This method returns a clone of this instance.
Exception
NA
Cloning a Locale of CANADA Example
The following example shows the usage of Java Locale clone() method. We're creating an instance of a Locale of Canada. Locale is printed and its clone is created and printed.
package com.tutorialspoint;
import java.util.Locale;
public class LocaleDemo {
public static void main(String[] args) {
// create a new locale
Locale locale1 = Locale.CANADA;
// print this locale
System.out.println("Locale1:" + locale1);
// create a second locale
Locale locale2;
// clone locale1 to locale2
locale2 = (Locale) locale1.clone();
// print locale2
System.out.println("Locale2:" + locale2);
}
}
Output
Let us compile and run the above program, this will produce the following result −
Locale1:en_CA Locale2:en_CA
Cloning a Locale of US Example
The following example shows the usage of Java Locale clone() method. We're creating an instance of a Locale of US. Locale is printed and its clone is created and printed.
package com.tutorialspoint;
import java.util.Locale;
public class LocaleDemo {
public static void main(String[] args) {
// create a new locale
Locale locale1 = Locale.US;
// print this locale
System.out.println("Locale1:" + locale1);
// create a second locale
Locale locale2;
// clone locale1 to locale2
locale2 = (Locale) locale1.clone();
// print locale2
System.out.println("Locale2:" + locale2);
}
}
Output
Let us compile and run the above program, this will produce the following result −
Locale1:en_US Locale2:en_US
Cloning a Locale of FRANCE Example
The following example shows the usage of Java Locale clone() method. We're creating an instance of a Locale of France. Locale is printed and its clone is created and printed.
package com.tutorialspoint;
import java.util.Locale;
public class LocaleDemo {
public static void main(String[] args) {
// create a new locale
Locale locale1 = Locale.FRANCE;
// print this locale
System.out.println("Locale1:" + locale1);
// create a second locale
Locale locale2;
// clone locale1 to locale2
locale2 = (Locale) locale1.clone();
// print locale2
System.out.println("Locale2:" + locale2);
}
}
Output
Let us compile and run the above program, this will produce the following result −
Locale1:fr_FR Locale2:fr_FR