ChronoField valueOf() method in Java with Examples
Last Updated :
29 Jan, 2020
The valueOf() method of ChronoField enum is used to return the enum constant of this type with the specified name.
Syntax:
public static ChronoField valueOf(String name)
Parameters: This method accepts name which is the name of the enum constant to be returned.
Return value: This method returns the enum constant with the specified name.
Below programs illustrate the ChronoField.valueOf() method:
Program 1:
import java.time.temporal.ChronoField;
public class GFG {
public static void main(String[] args)
{
ChronoField chronoField
= ChronoField.valueOf( "HOUR_OF_DAY" );
System.out.println( "ENUM: "
+ chronoField);
}
}
|
Program 2:
import java.time.temporal.ChronoField;
public class GFG {
public static void main(String[] args)
{
ChronoField chronoField
= ChronoField.valueOf( "YEAR_OF_ERA" );
System.out.println( "ENUM: "
+ chronoField);
}
}
|
References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/ChronoField.html#valueOf(java.lang.String)
Share your thoughts in the comments
Please Login to comment...