Properties clone() method in Java with Examples
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:
// Java code illustrating clone() method 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", "contribute.geeksforgeeks.org"); gfg.put("quiz", "quiz.geeksforgeeks.org"); // checking what's in table System.out.println("Current Properties: " + gfg.toString()); System.out.println("\nCloning the Properties"); Properties cloned = (Properties)gfg.clone(); // checking what's in table now System.out.println("Cloned Properties: " + cloned.toString()); } } |
Current Properties: {contribute=contribute.geeksforgeeks.org, quiz=quiz.geeksforgeeks.org, ide=ide.geeksforgeeks.org}
Cloning the Properties
Cloned Properties: {contribute=contribute.geeksforgeeks.org, quiz=quiz.geeksforgeeks.org, ide=ide.geeksforgeeks.org}
Example 2:
// Java code illustrating clone() method 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"); // checking what's in table System.out.println("Current Properties: " + gfg.toString()); System.out.println("\nCloning the Properties"); Properties cloned = (Properties)gfg.clone(); // checking what's in table now System.out.println("Cloned Properties: " + cloned.toString()); } } |
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–
Recommended Posts:
- DecimalFormatSymbols clone() method in Java with Examples
- StringCharacterIterator clone() method in Java with Examples
- NumberFormat clone() method in Java with Examples
- Vector clone() Method in Java with Examples
- SimpleDateFormat clone() Method in Java with Examples
- Calendar clone() Method in Java with Examples
- BitSet clone() Method in Java with Examples
- DateFormat clone() method in Java with Examples
- TimeZone clone() Method in Java with Examples
- ConcurrentSkipListMap clone() method in Java with Examples
- Date clone() method in Java with Examples
- Locale clone() Method in Java with Examples
- ArrayList clone() method in Java with Examples
- CharacterIterator clone() method in Java with Examples
- SimpleTimeZone clone() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



