我想使用Properties类填充HashMap.我想加载.propeties文件中的条目,然后将其复制到HashMap中.
此前,我曾经使用属性文件初始化HashMap,但是现在我已经定义了HashMap,并希望仅在构造函数中初始化它.
早期方法:
@H_301_6@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);但现在,我有这个
@H_301_6@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 } }在这里如何将属性对象分配给HashMap?