Period withYears() method in Java with Examples
The withYears() method of Period Class is used to obtain a period with specified number of years. This number of years is passed as the parameter as integer value.
public Period withYears(int numberOfYears)
Parameters: This method accepts a parameter numberOfYears which is the number of years to be changed in this Period.
Returns: This function returns a Period with the number of years passed as the parameter.
Below is the implementation of Period.withYears() method:
Period: P1Y2M21D New Period: P5Y2M21D
Period: P-1Y-2M-21D New Period: P-5Y-2M-21D
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.