Open In App

SignStyle valueOf() method in Java with Examples

Improve
Improve
Like Article
Like
Save
Share
Report

The valueOf() method of SignStyle enum is used to return the enum of this type SignStyle with the specified name.

Syntax:

public static SignStyle 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 SignStyle.valueOf() method:
Program 1:




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


Output:

SignStyle: NOT_NEGATIVE

Program 2:




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


Output:

SignStyle: NEVER

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



Last Updated : 04 Feb, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads