简体   繁体   中英

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.

If you must get it into another Map , just use Map.putAll() .

Use .entrySet() and iterate over .properties entries.

for (final Entry<Object, Object> entry :   properties.entrySet()) { 
map.put((String) entry.getKey(), (String) entry.getValue()); }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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