Calendar roll(int calndr_field, int amt) method in Java with Examples
The roll(int calndr_field, int amt) method in Calendar class is used to operate on the passed calendar field by adding the passed amount to a specific calendar field without the alteration of large field values.
Note: The positive amount must be added and the negative amount must be subtracted.
public void roll(int calndr_field, int amt)
Parameters: The method takes two parameters:
- calndr_field: This is of Calendar type and refers to the field of the calendar that is to be operated upon.
- amt: This is of the Integer type that is to be added or subtracted depending upon the sign of the value.
Return Value: The method does not return any value.
Below programs illustrate the working of roll() Method of Calendar class:
The Current Year is: 2019 The New Year is: 2014 The new year is: 2016
The Current Month is: 2 The New Month is: 5 The new month is: 4
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.