Java Utility Library

Java Locale - clone() Method



The java.util.Locale.clone() method returns a copy of this locale.

Syntax

public Object clone()

Parameters

No parameter is required.

Return Value

Returns a copy of this locale instance.

Exception

NA

Example:

In the example below, the java.util.Locale.clone() method is used to create a copy of the given locale instance.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a locale
    Locale loc1 = new Locale("EN", "US");

    //printing loc1
    System.out.println("loc1 is: " + loc1);

    //creating a second locale
    Locale loc2;

    //creating a clone of loc1 into loc2
    loc2 = (Locale)loc1.clone();

    //printing loc2
    System.out.println("loc2 is: " + loc2);
  }
}

The output of the above code will be:

loc1 is: en_US
loc2 is: en_US

❮ Java.util - Locale