import java.util.Properties; public class Main { public static void main(String[] args) { Properties original = new Properties(); original.setProperty("name", "John"); original.setProperty("age", "30"); Properties copy = (Properties) original.clone(); System.out.println("Original: " + original); System.out.println("Copy: " + copy); } }
Original: {name=John, age=30} Copy: {name=John, age=30}
import java.io.IOException; import java.io.InputStream; import java.util.Properties; public class Main { public static void main(String[] args) throws IOException { InputStream inputStream = Main.class.getClassLoader().getResourceAsStream("config.properties"); Properties properties = new Properties(); properties.load(inputStream); Properties copy = (Properties) properties.clone(); System.out.println("Original: " + properties); System.out.println("Copy: " + copy); } }
Original: {name=John, age=30} Copy: {name=John, age=30}The java.util.Properties class is part of the Java Standard Library.