Friday, September 26, 2025
HomeLanguagesJavaFormatStyle valueOf() method in Java with Examples

FormatStyle valueOf() method in Java with Examples

The valueOf() method of a FormatStyle enum is used to get the enum value of this type FormatStyle with the specified name.

Syntax:

public static FormatStyle valueOf(String name)

Parameters: This method accepts a name as the parameter which is the name of the enum constant to be returned.

Return value: This method returns the enum constant with the specified name.

Exceptions: This method throws the following exception:

  • IllegalArgumentException: if this enum type has no constant with the specified name.
  • NullPointerException: if the argument is null.

Below programs illustrate the FormatStyle.valueOf() method:
Program 1:




// Java program to demonstrate
// FormatStyle.valueOf() method
  
import java.time.format.FormatStyle;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // Get FormatStyle instance
        FormatStyle formatStyle
            = FormatStyle.valueOf("LONG");
  
        // Print the result
        System.out.println("FormatStyle: "
                           + formatStyle);
    }
}


Output:

FormatStyle: LONG

Program 2:




// Java program to demonstrate
// FormatStyle.valueOf() method
  
import java.time.format.FormatStyle;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // Get FormatStyle instance
        FormatStyle formatStyle
            = FormatStyle.valueOf("FULL");
  
        // Print the result
        System.out.println("FormatStyle: "
                           + formatStyle);
    }
}


Output:

FormatStyle: FULL

References: https://docs.oracle.com/javase/10/docs/api/java/time/format/FormatStyle.html

RELATED ARTICLES

Most Popular

Dominic
32321 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6683 POSTS0 COMMENTS
Nicole Veronica
11854 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11910 POSTS0 COMMENTS
Shaida Kate Naidoo
6795 POSTS0 COMMENTS
Ted Musemwa
7071 POSTS0 COMMENTS
Thapelo Manthata
6757 POSTS0 COMMENTS
Umr Jansen
6762 POSTS0 COMMENTS