I have to replace HashMap keys based on a property file mapping with old - new key mapping. Is the below approach best way of replacing keys?
KeyMapping.properties
newKey1 oldLKey1
newKey2 oldKey2
//Load property mapping file
ResourceBundle properties = ResourceBundle.getBundle("KeyMapping");
Enumeration<String> newKeys = properties.getKeys();
Map<String, Object> result = new LinkedHashMap<>();
while (newKeys.hasMoreElements()) {
String newKey = (String) newKeys.nextElement();
Iterator<Entry<String, Object>> iterator = mapToReplaceKeys.entrySet().iterator();
while(iterator.hasNext()) {
Entry<String, Object> entry = iterator.next();
//If key matches the key in property file
if (entry.getKey().equals(newKey)) {
//remove the entry from map mapToReplaceKeys
iterator.remove();
//add the key with the 'oldKey' and existing value
result.put(properties.getString(newKey), entry.getValue());
}
}
}