If the Calendar is on the last day of the month (say 31st of July) , will
Look at the documentation of the superclass
java.util.Calendar, in the section named "Field Manipulation" (emphasis mine):
f. This is equivalent to calling
set(f, get(f) + delta)with two adjustments:
Add rule 1. The value of field
fafter the call minus the value of field
fbefore the call is
delta, modulo any overflow that has occurred in field
f. Overflow occurs when a field value exceeds its range and, as a result, the next larger field is incremented or decremented and the field value is adjusted back into its range.
add(Calendar.DAY_OF_MONTH, 1) will change 31st of July to 1st of August.
In contrast, the documentation continues:
fwithout changing larger fields. This is equivalent to calling
add(f, delta)with the following adjustment:
Roll rule. Larger fields are unchanged after the call. A larger field represents a larger unit of time.
DAY_OF_MONTHis a larger field than
roll(Calendar.DAY_OF_MONTH, 1) will change 31st of July to 1st of July.