Java Month create from String

Description

Java Month create from String

import java.time.Month;

public class Main {
  public static void main(String[] args) {
    Month month = null;//from   w ww . j  a  v  a  2 s.  c om

    try {
      month = Month.valueOf("MARCH");
      System.out.println(month);
    } catch (IllegalArgumentException exc) {
      System.out.printf("%s is not a valid month.%n", "MARCH");
      throw exc; // Rethrow the exception
    }
  }
}



PreviousNext

Related