1

I'm attempting to rewrite all the values in a properties file into a hashmap but when I attempt to run this code

for (String keys: properties.entrySet())
    {
        hMap.put(keys,  properties.get(keys));
    }

I get the following error.

The method put(String, String) in the type Map<String,String> is not applicable for the arguments (Map.Entry<Object,Object>, Object)

I understand that one is a String type and one is a Object but I have no idea how to fix it becuase I'm pretty new to programming...

power5000
  • 25
  • 1
  • 9
  • Yeah it was a duplicate question... I've been trying to solve this for a while now and that thread helped a lot the larger issue was reading the properties from the file more than turning them into a hashmap.... thank you again and sorry for the repeat.... – power5000 May 14 '15 at 02:07

2 Answers2

2

You get Map.Entry as the return type of Properties.entrySet().

for (Map.Entry entry: properties.entrySet(
{
   hMap.put((String)entry.getKey(),  (String)entry.getValue());
}
Eranda
  • 1,439
  • 1
  • 17
  • 30
0

This should work for you:

for (String keys: properties.stringPropertyNames())  
{
        hMap.put(keys,  properties.get(keys));
}
Steephen
  • 14,645
  • 7
  • 40
  • 47