Java Date Time - Month valueOf(String name) example








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 www. ja  va2s .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.