The Java Locale clone() method creates a copy of this locale.
DeclarationFollowing is the declaration for java.util.Locale.clone() method
public Object clone()Parameters
NA
Return ValueThis method returns a clone of this instance.
ExceptionNA
Cloning a Locale of CANADA ExampleThe 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_CACloning 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_USCloning 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
java_util_locale.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4