I'm doing a project similar to an expense manager in Java (every expense has a date and an amount), where I have to make a report. The report should report the cumulative totals of expenses for each year and each month (of the same year). But I do not want him to take all the expenses to make the report. The idea is to enter a range of time (such as: February 2016 to March 2018) where only expenses that fall within that range will be taken into account. Is there a library or algorithm to do this?