Month values() example
Description
Month values()
returns an array containing
the constants of this enum type, in the order they are declared.
Syntax
values
has the following syntax.
public static Month[] values()
Example
The following example shows how to use values
.
import java.time.Month;
/*from w w w. j av a2 s . c om*/
public class Main {
public static void main(String[] args) {
for (Month c : Month.values())
System.out.println(c);
}
}
The code above generates the following result.
Example 2
Display the number of days in each month of the specified year
import java.time.Month;
import java.time.YearMonth;
//from w w w . j a v a 2 s.c o m
public class Main {
public static void main(String[] args) {
for (Month month : Month.values()) {
YearMonth ym = YearMonth.of(2014, month);
System.out.printf("%s: %d days%n", month, ym.lengthOfMonth());
}
}
}
The code above generates the following result.