Sunday, February 1, 2026
HomeLanguagesJavaYear adjustInto() Method in Java with Examples

Year adjustInto() Method in Java with Examples

adjustInto() method of the Year class used to adjusts the passed temporal object to have this year on which this method is applied.This instance is immutable and unaffected by this method call.

Syntax:

public Temporal adjustInto(Temporal temporal)

Parameters: This method accepts temporal as parameter which is the target temporal object to be adjusted. It should not be null.

Return value: This method returns the adjusted object.

Exception: This method throws following Exceptions:

  • DateTimeException – if unable to make the adjustment.
  • ArithmeticException – if numeric overflow occurs.

Below programs illustrate the adjustInto() method:
Program 1:




// Java program to demonstrate
// Year.adjustInto() method
  
import java.time.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create a Year object
        Year yr
            = Year.of(2019);
  
        // create a temporal object
        LocalDate date = LocalDate.parse("2007-12-03");
  
        // print instance
        System.out.println("LocalDate :"
                           + date);
  
        // apply adjustInto method of Year class
        LocalDate updatedlocal = (LocalDate)yr.adjustInto(date);
  
        // print instance
        System.out.println("LocalDate after"
                           + " applying adjustInto method: "
                           + updatedlocal);
    }
}


Output:

LocalDate :2007-12-03
LocalDate after applying adjustInto method: 2019-12-03

Program 2:




// Java program to demonstrate
// Year.adjustInto() method
  
import java.time.*;
  
public class GFG {
    public static void main(String[] args)
    {
        // create a Year object
        Year yr
            = Year.of(2032);
  
        // create a temporal object
        LocalDate date = LocalDate.parse("2017-01-13");
  
        // print instance
        System.out.println("LocalDate :"
                           + date);
  
        // apply adjustInto method of Year class
        LocalDate updatedlocal = (LocalDate)yr.adjustInto(date);
  
        // print instance
        System.out.println("LocalDate after"
                           + " applying adjustInto method: "
                           + updatedlocal);
    }
}


Output:

LocalDate :2017-01-13
LocalDate after applying adjustInto method: 2032-01-13

References: https://docs.oracle.com/javase/10/docs/api/java/time/Year.html#adjustInto(java.time.temporal.Temporal)

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32478 POSTS0 COMMENTS
Milvus
123 POSTS0 COMMENTS
Nango Kala
6849 POSTS0 COMMENTS
Nicole Veronica
11978 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12066 POSTS0 COMMENTS
Shaida Kate Naidoo
6987 POSTS0 COMMENTS
Ted Musemwa
7222 POSTS0 COMMENTS
Thapelo Manthata
6934 POSTS0 COMMENTS
Umr Jansen
6917 POSTS0 COMMENTS