ChronoField valueOf() method in Java with Examples

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:



filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// ChronoField.valueOf() method
  
import java.time.temporal.ChronoField;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // get chronoField
        ChronoField chronoField
            = ChronoField.valueOf("HOUR_OF_DAY");
  
        // print
        System.out.println("ENUM: "
                           + chronoField);
    }
}

chevron_right


Output:

ENUM: HourOfDay

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// ChronoField.valueOf() method
  
import java.time.temporal.ChronoField;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // get chronoField
        ChronoField chronoField
            = ChronoField.valueOf("YEAR_OF_ERA");
  
        // print
        System.out.println("ENUM: "
                           + chronoField);
    }
}

chevron_right


Output:

ENUM: YearOfEra

References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/ChronoField.html#valueOf(java.lang.String)

Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up

I am a Developer I love to code and bring my ideas alive

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.