Map<string, List<Object>> finalMap = new Map<string, List<Object>>();
for(Map<String, Object> cus : allJSONValues){
for(string key : cus.keyset()){
if(finalMap.containsKey(key)){
finalMap.get(key).add(cus.get(key));
}else {
List<Object> newObj = new List<Object>();
newObj.add(cus.get(key));
finalMap.put(key,newObj);
}
}
}
allJSONValues is a List<Map<String, Object>>.
Can anyone please tell me how can I optimize this and can remove double for loop from this.