ChronoField values() method in Java with Examples
Last Updated :
29 Jan, 2020
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:
import java.time.temporal.ChronoField;
public class GFG {
public static void main(String[] args)
{
ChronoField chronoField
= ChronoField.valueOf( "HOUR_OF_DAY" );
ChronoField[] array
= chronoField.values();
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:
import java.time.temporal.ChronoField;
public class GFG {
public static void main(String[] args)
{
ChronoField chronoField
= ChronoField.valueOf( "HOUR_OF_DAY" );
ChronoField[] array
= chronoField.values();
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()
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...