Friday, February 6, 2026
HomeLanguagesJavaChronoField values() method in Java with Examples

ChronoField values() method in Java with Examples

The values() method of ChronoField enum is used to an array containing the constants of this enum type, in the order, they are declared.

Syntax:

public static ChronoField[] values()

Parameters: This method accepts nothing.

Return value: This method returns an array containing the constants of this enum type, in the order, they are declared.

Below programs illustrate the ChronoField.values() method:
Program 1:




// Java program to demonstrate
// ChronoField.values() method
  
import java.time.temporal.ChronoField;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // get chronoField
        ChronoField chronoField
            = ChronoField.valueOf("HOUR_OF_DAY");
  
        // apply values()
        ChronoField[] array
            = chronoField.values();
  
        // print
        for (int i = 0; i < array.length; i++)
            System.out.println(array[i]);
    }
}


Output:

NanoOfSecond
NanoOfDay
MicroOfSecond
MicroOfDay
MilliOfSecond
MilliOfDay
SecondOfMinute
SecondOfDay
MinuteOfHour
MinuteOfDay
HourOfAmPm
ClockHourOfAmPm
HourOfDay
ClockHourOfDay
AmPmOfDay
DayOfWeek
AlignedDayOfWeekInMonth
AlignedDayOfWeekInYear
DayOfMonth
DayOfYear
EpochDay
AlignedWeekOfMonth
AlignedWeekOfYear
MonthOfYear
ProlepticMonth
YearOfEra
Year
Era
InstantSeconds
OffsetSeconds

Program 2:




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


Output:

ChronoField length:30

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

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32489 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6862 POSTS0 COMMENTS
Nicole Veronica
11983 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12073 POSTS0 COMMENTS
Shaida Kate Naidoo
6995 POSTS0 COMMENTS
Ted Musemwa
7236 POSTS0 COMMENTS
Thapelo Manthata
6946 POSTS0 COMMENTS
Umr Jansen
6930 POSTS0 COMMENTS