I have a map as below:
Map<Integer, List<String>> iMap = new Map<Integer, List<String>>{
1 => new List<String>{'a','b','c'},
2 => new List<String>{'d','e','f'}
};
What I am trying is to combine the 2 list values for above map which if done as below outputs as (a,b,c,d,e,f)
List<String> combinedList = new List<String>();
combinedList.addAll(iMap.get(1));
combinedList.addAll(iMap.get(2));
but I am looking to out put above list as (a,d,b,e,c,f)
{one value from each key of the map}
I tried to do as shown below which didnt work and obviously doing same as above. Looking for suggestions.
Integer totalCount = combinedList.size();
List<String> returnList = new String[totalCount];
for(Integer i = 0; i < totalCount; i++){
/*1*/if(math.mod(i+1, 2) != 0) returnList.set(i, combinedList.get(i));
/*2*/else returnList.set(i, combinedList.get(i));
}
system.debug(returnList);
*** Map defined above will have lists of equal size (though solution for unequal size will be more ideal for me)