Метод Properties clone () в Java с примерами
Метод Java.util.Properties.clone () используется для создания неглубокой копии этого экземпляра со всеми элементами из этого экземпляра Properties.
Синтаксис:
клон общедоступного объекта ()
Параметры: метод не принимает никаких параметров
Возвращаемое значение: функция возвращает клонированный объект, который является мелкой копией этого экземпляра Properties.
Ниже программы иллюстрируют метод Java.util.Properties.clone ().
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( "
Cloning 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( "
Cloning 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}
Ссылка: https://docs.oracle.com/javase/9/docs/api/java/util/Properties.html#clone–
Вниманию читателя! Не переставай учиться сейчас. Ознакомьтесь со всеми важными концепциями Java Foundation и коллекций с помощью курса "Основы Java и Java Collections" по доступной для студентов цене и будьте готовы к работе в отрасли. Чтобы завершить подготовку от изучения языка к DS Algo и многому другому, см. Полный курс подготовки к собеседованию .