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:
// 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()); } } |
2018
Program 2:
// 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()); } } |
1997
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/Year.html#toString–
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Year with() Method in Java with Examples
- Year from() Method in Java with Examples
- Year of() method in Java with Examples
- Year now() method in Java with examples
- Year until() Method in Java with Examples
- Year get() method in Java with Examples
- Constructor toString() method in Java with Examples
- Scanner toString() method in Java with Examples
- Calendar toString() Method in Java with Examples
- StringBuilder toString() method in Java with Examples
- Field toString() method in Java with Examples
- OffsetTime toString() method in Java with examples
- LocalTime toString() method in Java with Examples
- WeekFields toString() method in Java with Examples
- ValueRange toString() method in Java with Examples
- LongAdder toString() method in Java with Examples
- AtomicLong toString() method in Java with examples
- String toString() Method in java with Examples
- Pattern toString() Method in Java with Examples
- Package toString() method in Java with Examples
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.

