简体   繁体   English

如何将属性文件中的所有值作为键传递给哈希表

[英]How to pass all values from properties file as key to hashmap

I have a proprieties file which consist of few extries 我有一个包含几个引号的专有文件

a = true
b = yes
c = X
d = Y
e = true
r = yes

I would like to read this file and pass all the keys as key to hashmap and depending on which keys are present in hashmap, need to update the value 我想读取此文件并将所有键作为键传递给哈希图,并根据哈希图中存在的键,需要更新值

for (String key : properties.stringPropertyNames()) {
    String value = properties.getProperty(key);
    mymap.put(key, Integer.valueOf(value));
}

It is not taking all the entries from properties file.. Can any one provide any other approach 它没有从属性文件中获取所有条目。.任何人都可以提供任何其他方法

There is no problem here to solve. 这里没有问题可以解决。 Properties is already a hash map. Properties 已经是一个哈希映射。

If you must get it into another Map , just use Map.putAll() . 如果必须将其放入另一个Map ,则只需使用Map.putAll()

Use .entrySet() and iterate over .properties entries. 使用.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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM