I have multiple records received as string through a query. I want to store records having the same "long" key in a collection dynamically as I parse them in a loop. Like, insert key and value and if the key exists, it adds to the values and if not, a new key is created. What would be the most efficient way of doing this? I can do it using multiple arrays but I would prefer a cleaner way.
I cannot use a HashMap as I have to first store the records in an Array or ArrayList and then insert it which defeats the purpose as I have to group the lists by key first anyway. The no. of records will not more than 50 at a time.
E.g data:
for(i = 0; i < numRecords; i++ ) {
Data: 1 "A", 2 "B", 1 "C", 3 "D", 1 "E"
}
I want to have a collection where inside the loop I can just add: 1 "A" and so on..