I have a nested loop in the code below which I'm trying to optimize as I know nested for loop is very expensive, anyone has a different way to achieve this?
Thanks in advance!
private List<Map<String, Object>> updateSomething(List<Map<String, Object>> list)
throws MetadataException {
for (Map<String, Object> map : list) {
setFilePathAndOffsetParams(map);
for (Map.Entry<String, String> entry : anotherMap.entrySet()) {
updateKeyOnMap(map, entry.getKey(), entry.getValue());
}
}
return list;
}
private void updateKeyOnMap(Map<String, Object> map, String newKey, String oldKey) {
if (!newKey.equals(oldKey)) {
map.put(newKey, map.get(oldKey));
map.remove(oldKey);
}