This content has been marked as final. Show 4 replies
Basically your situation is that you have a "stream" of tokens in which the same key may appear multiple times but with a different value; in other words you have one key which is bound to multiple values.
I don't know, but a HashMap with an ArrayList as its value can easily store that. It would be something like:
Map<String,List<String>> values = new HashMap<String,List<String>>();
2. for each key/value pair...
2a. fetch List from HashMap for key K
2b. if list is null, create it (ArrayList) and put it in the HashMap under key K
2c. add value V to the list
Nice and dumb.
I would suggest parsing your input should give you those "tokens" you are talking about,
you should store these keys and values to a Map<String,List<String>>
or possibly a Map<String,Set<String>>, depending on how you want to handle duplicate value entries.
java KeyValueList "K1,V1;K1,V2;K2,V3;K2,V4;K3,V5;K3,V5" K1: [V1, V2] K2: [V3, V4] K3: [V5, V5] java KeyValueSet "K1,V1;K1,V2;K2,V3;K2,V4;K3,V5;K3,V5" K1: [V2, V1] K2: [V3, V4] K3: [V5]