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:
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
Year thisYear = Year.of( 2018 );
System.out.println(thisYear.toString());
}
}
|
Program 2:
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
Year thisYear = Year.of( 1997 );
System.out.println(thisYear.toString());
}
}
|
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/Year.html#toString–
Last Updated :
27 Nov, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...