Month valueOf(String name) example

Description

Month valueOf(String name) returns the enum constant of this type with the specified name.

Syntax

valueOf has the following syntax.


public static Month valueOf(String name)

Example

The following example shows how to use valueOf.


import java.time.Month;
//from ww  w . j a v a  2  s.c o  m
public class Main {
  public static void main(String[] args) {
    Month m = Month.valueOf("MAY");
    System.out.println(m.getValue());
    System.out.println(m.name());
    System.out.println(m.ordinal());
  }
}

The code above generates the following result.





















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset