[英]How to pass all values from properties file as key to hashmap
我有一个包含几个引号的专有文件
a = true
b = yes
c = X
d = Y
e = true
r = yes
我想读取此文件并将所有键作为键传递给哈希图,并根据哈希图中存在的键,需要更新值
for (String key : properties.stringPropertyNames()) {
String value = properties.getProperty(key);
mymap.put(key, Integer.valueOf(value));
}
它没有从属性文件中获取所有条目。.任何人都可以提供任何其他方法
这里没有问题可以解决。 Properties
已经是一个哈希映射。
如果必须将其放入另一个Map
,则只需使用Map.putAll()
。
使用.entrySet()并遍历.properties条目。
for (final Entry<Object, Object> entry : properties.entrySet()) {
map.put((String) entry.getKey(), (String) entry.getValue()); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.