Year toString() method in Java with Examples

The toString() method of Year class in Java is used to return the string representation of this Year object.

Syntax:

public String toString()

Parameter: This method does not accepts any parameter.

Return Value: It returns the string representation of this Year object.

Below programs illustrate the toString() method of Year in Java:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Program to illustrate the toString() method
  
import java.util.*;
import java.time.*;
  
public class GfG {
    public static void main(String[] args)
    {
        // Create a valid Year object
        Year thisYear = Year.of(2018);
  
        // Print the string representation
        System.out.println(thisYear.toString());
    }
}

chevron_right


Output:

2018

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Program to illustrate the toString() method
  
import java.util.*;
import java.time.*;
  
public class GfG {
    public static void main(String[] args)
    {
        // Create a valid Year object
        Year thisYear = Year.of(1997);
  
        // Print the string representation
        System.out.println(thisYear.toString());
    }
}

chevron_right


Output:

1997

Reference: https://docs.oracle.com/javase/8/docs/api/java/time/Year.html#toString–



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.