Java - plusXXX( ) and minusXXX( ) Methods

Introduction

plusXXX() method returns a copy of an object by adding a specified value.

For example, the plusDays(long days) method from LocalDate class returns a copy of the LocalDate object by adding the specified number of days.

minusXXX() method returns a copy of an object by subtracting a specified value.

For example, the minusDays(long days) method in the LocalDate class returns a copy of the LocalDate object by subtracting the specified number of days.

Demo

import java.time.LocalDate;

public class Main {
  public static void main(String[] args) {
    LocalDate ld = LocalDate.of(2012, 5, 2); // 2012-05-02
    System.out.println(ld);//from w  ww.j  a  va2  s  .  co  m
    LocalDate ld1 = ld.plusDays(5);          // 2012-05-07
    System.out.println(ld1);
    LocalDate ld2 = ld.plusMonths(3);        // 2012-08-02
    System.out.println(ld2);
    LocalDate ld3 = ld.plusWeeks(3);         // 2012-05-23
    System.out.println(ld3);
    LocalDate ld4 = ld.minusMonths(7);       // 2011-10-02
    System.out.println(ld4);
    LocalDate ld5 = ld.minusWeeks(3);        // 2012-04-11
    System.out.println(ld5);
  }
}

Result