this code:
import java.util.Properties;
public class P {
public static void main(String[] args) {
Properties defaultProperties=new Properties();
defaultProperties.put("a",1);
System.out.println("default: "+defaultProperties);
Properties properties=new Properties(defaultProperties);
System.out.println("other: "+properties);
}
}
prints:
default: {a=1}
other: {}
using java 8 in eclipse luna.
how should one construct a properties list with defaults?
The are 2 problems with your code.
get() and put().You instead need to do setProperty() and 'getProperty()`.
toString() method is not so sophesticated.Use this instead:
Properties defaultProperties=new Properties();
defaultProperties.setProperty("a","s");
System.out.println("default: "+defaultProperties);
Properties properties=new Properties(defaultProperties);
System.out.println("other: "+properties.getProperty("a"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With