I have an array list of events, and I would like to convert them to a mutable map where one of the event values (date) is the key, and each key contains only events with that date. Below is an example of my original event list:
[Event(name="person 1", desc="hello", date="2021-01-05"),
Event(name="person 2", desc="hi", date="2021-01-05"),
Event(name="person 3", desc="hi", date="2021-01-08")]
By iterating though events and adding the key and events each time, I so far get this result:
{2021-01-05=[Event(name="person 1", desc="hello", date="2021-01-05"),
Event(name="person 2", desc="hi", date="2021-01-05"),
Event(name="person 3", desc="hi", date="2021-01-08")],
2021-01-08=[Event(name="person 1", desc="hello", date="2021-01-05"),
Event(name="person 2", desc="hi", date="2021-01-05"),
Event(name="person 3", desc="hi", date="2021-01-08")]}
The result below is what I need, but I am not sure how I would go about getting it. I've tried filtering the map and iterating again, but just cannot get the desired result. Any help would be appreciated.
{2021-01-05=[Event(name="person 1", desc="hello", date="2021-01-05"),
Event(name="person 2", desc="hi", date="2021-01-05")],
2021-01-08=[Event(name="person 3", desc="hi", date="2021-01-08")]}
question from:
https://stackoverflow.com/questions/65911235/how-to-convert-array-list-to-map-matching-keys-to-array-value