Home » Java programming language

Java Locale clone() Method With Example

Locale Class clone() method: Here, we are going to learn about the clone() method of Locale Class with its syntax and example.
Submitted by Preeti Jain, on March 08, 2020

Locale Class clone() method

  • clone() method is available in java.util package.
  • clone() method is used to return clone copy or shallow copy of this Locale.
  • clone() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • clone() method does not throw an exception at the time of cloning an object.

Syntax:

    public Object clone();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of the method is Object, it returns cloned object of this Locale.

Example:

// Java program to demonstrate the example 
// of Object clone() method of Locale 

import java.util.*;

public class CloneOfLocale {
    public static void main(String[] args) {
        // Instantiates Locale objects
        Locale lo = new Locale("FRANCE", "JAPAN", "GERMANY");
        Locale clone_lo = new Locale("US");

        // Display Locale lo, clone_lo
        System.out.println("lo: " + lo);
        System.out.println("clone_lo: " + clone_lo);

        System.out.println();

        // By using clone() method is
        // to clone this object lo
        clone_lo = (Locale) lo.clone();

        // Display Locale lo, clone_lo
        System.out.println("lo: " + lo);
        System.out.println("lo.clone(): " + clone_lo);
    }
}

Output

lo: france_JAPAN_GERMANY
clone_lo: us

lo: france_JAPAN_GERMANY
lo.clone(): france_JAPAN_GERMANY






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.