how to construct properties list with defaults in java? -


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 1 construct properties list defaults?

the 2 problems code.

  1. the default properties don't work when use get() , put().

you instead need setproperty() , 'getproperty()`.

  1. when print properties file, wont include default properties. tostring() method not sophesticated.

use 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")); 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -