java - Populating a HashMap with entries from a properties file -
i want populate hashmap
using properties
class. want load entries in .propeties
file , copy hashmap
.
earlier, used initialize hashmap
properties file, have defined hashmap
, want initialize in constructor only.
earlier approach:
properties properties = new properties(); try { properties.load(classname.class.getresourceasstream("resume.properties")); } catch (exception e) { } hashmap<string, string> mymap= new hashmap<string, string>((map) properties);
but now, have this
public class classname { hashmap<string,integer> mymap = new hashmap<string, integer>(); public classname(){ properties properties = new properties(); try { properties.load(classname.class.getresourceasstream("resume.properties")); } catch (exception e) { } mymap = properties; //the above line gives error } }
how assign properties object hashmap
here ?
if understand correctly, each value in properties string represents integer. code this:
for (string key : properties.stringpropertynames()) { string value = properties.getproperty(key); mymap.put(key, integer.valueof(value)); }
Comments
Post a Comment