Saturday, December 6, 2025
HomeLanguagesJavaChronoField valueOf() method in Java with Examples

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:




// 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);
    }
}


Output:

ENUM: HourOfDay

Program 2:




// 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);
    }
}


Output:

ENUM: YearOfEra

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

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32427 POSTS0 COMMENTS
Milvus
103 POSTS0 COMMENTS
Nango Kala
6802 POSTS0 COMMENTS
Nicole Veronica
11944 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12012 POSTS0 COMMENTS
Shaida Kate Naidoo
6932 POSTS0 COMMENTS
Ted Musemwa
7185 POSTS0 COMMENTS
Thapelo Manthata
6881 POSTS0 COMMENTS
Umr Jansen
6867 POSTS0 COMMENTS