Open In App

Locale clone() Method in Java with Examples

Last Updated : 27 Dec, 2018
Improve
Improve
Like Article
Like
Save
Share
Report

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:




// 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);
    }
}


Output:

First Locale: no_NO_NY
Second Locale: no_NO_NY

Program 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);
    }
}


Output:

First Locale: ga_IE
Second Locale: ga_IE


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads