I have a scenario for which I am looking for the most efficient approach.
I have key value pairs coming to the system in form of a long
string
for e.g. K1,V1;K1,V2;K2,V3;K2V4;K3,V5
I need to display it in form of
K1: V1,V2
K2: V3,V4
K3: V5
Approach I am thinking:
Steps:
1. create string tokens token 1 - K1,V1 token 2 - K1V2 etc, add them to a list
KeyValuesRawList
2. create string tokens token 1 K1, token 2 K2 etc, add them to a list
KeyList
4. create a map
finalMap, lists
valueList1,
valueList2,
valueList3
3. Iterate through
KeyValuesRawList,
3.1 create tokens tempK and tempV
3.2 if (tempK = K1)
add tempV to valueList1
if(tempK = K2)
add tempV to valueList2
if(tempK = K3)
add tempV to valueList3
3.3 Add values from list KeyList as keys to finalMap
3.4 Add values from lists valueList1,valueList2,valueList3 as values to finalMap