How to tabulate data grouped by month AND year using Java 8 streams

Viewed 1524

Assuming I have the simple POJO Meal:

public class Meal
{
    LocalDate mealtime;
    int calories;
}

which is then collected in a List:

List<Meals> meals;

How I can use streams to get a list that totals the calories consumed on a monthly basis over several years. It's very easy to tabulate based on the month alone but I want to create a bar chart spread over several years to compare the consumption of calories over time and NOT just by month.

How can this be done? Do I have to create some complex structure of Instant objects with months and Years using HashMaps of years and months or is there a better way?

1 Answers
Related