Your question is confusing, but I can get you started. I do suggest you rewrite your question to be crystal clear, for your own benefit, to come to understand your problem thoroughly in plain language before you start coding.
First use precise terms to clarify your thinking. You do not start with an ArrayList of date, you have an ArrayList of integer numbers that represent day-of-month.
Next you need today's date. That requires a time zone. For any given moment the date varies around the globe by zone.
ZoneId z = ZoneId.of( "America/Montreal" );
The LocalDate
class represents a date-only value without time-of-day and without time zone.
LocalDate today = LocalDate.now( z );
You might find YearMonth
class handy.
YearMonth ym = YearMonth.from( today );
You can get a date from that YearMonth.
LocalDate ld = ym.atDay( 15 );
You can get last day of month.
LocalDate endOfMonth = ym.atEndOfMonth();
You can do math, adding or subtracting months to the YearMonth.
YearMonth previousYm = ym.minusMonths( 1 );
You can retrieve a day-of-month from a LocalDate.
int dayOfMonth = myLocalDate.getDayOfMonth();
You can increment LocalDate with plus and minus methods.
LocalDate nextDate = myLocalDate.plusDays( 1 );
You should be able to put those pieces together to perform your particular business logic.
Tip: Stay away from the troublesome old legacy date-time classes. Use only java.time classes.
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old date-time classes such as java.util.Date
, .Calendar
, & java.text.SimpleDateFormat
.
The Joda-Time project, now in maintenance mode, advises migration to java.time.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations.
Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport and further adapted to Android in ThreeTenABP (see How to use…).
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval
, YearWeek
, YearQuarter
, and more.