Java.util.Locale.clone() Method

Advertisements


Description

The java.util.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

Example

The following example shows the usage of java.util.Locale.clone() method.

package com.tutorialspoint;

import java.util.*;

public class LocaleDemo {

   public static void main(String[] args) {

      // create a new locale
      Locale locale1 = new Locale("ENGLISH", "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);
   }
}

Let us compile and run the above program, this will produce the following result:

Locale1:english_US
Locale2:english_US



Advertisements
Advertisements