Properties clone() method in Java with Examples
Last Updated :
07 Dec, 2022
The Java.util.Properties.clone() method is used to create a shallow copy of this instance with all the elements from this Properties instance.
Syntax:
public Object clone()
Parameters: The method does not take any parameter
Return Value: The function returns the cloned Object which is the shallow copy of this Properties instance.
Below programs illustrate the Java.util.Properties.clone() method.
Example 1:
import java.util.*;
class PropertiesDemo {
public static void main(String arg[])
{
Properties gfg = new Properties();
Set URL;
String str;
gfg.put( "ide" ,
"ide.geeksforgeeks.org" );
gfg.put( "contribute" ,
"write.geeksforgeeks.org" );
gfg.put( "quiz" ,
"www.geeksforgeeks.org" );
System.out.println( "Current Properties: "
+ gfg.toString());
System.out.println( "\nCloning the Properties" );
Properties cloned = (Properties)gfg.clone();
System.out.println( "Cloned Properties: "
+ cloned.toString());
}
}
|
Output:
Current Properties: {contribute=write.geeksforgeeks.org, quiz=www.geeksforgeeks.org, ide=ide.geeksforgeeks.org}
Cloning the Properties
Cloned Properties: {contribute=write.geeksforgeeks.org, quiz=www.geeksforgeeks.org, ide=ide.geeksforgeeks.org}
Example 2:
import java.util.*;
class PropertiesDemo {
public static void main(String arg[])
{
Properties gfg = new Properties();
Set URL;
String str;
gfg.put( 1 , "Geeks" );
gfg.put( 2 , "GeeksforGeeks" );
gfg.put( 3 , "Geek" );
System.out.println( "Current Properties: "
+ gfg.toString());
System.out.println( "\nCloning the Properties" );
Properties cloned = (Properties)gfg.clone();
System.out.println( "Cloned Properties: "
+ cloned.toString());
}
}
|
Output:
Current Properties: {3=Geek, 2=GeeksforGeeks, 1=Geeks}
Cloning the Properties
Cloned Properties: {3=Geek, 2=GeeksforGeeks, 1=Geeks}
Reference: https://docs.oracle.com/javase/9/docs/api/java/util/Properties.html#clone–
Share your thoughts in the comments
Please Login to comment...