Thursday, June 18, 2026
HomeLanguagesJavaTextStyle valueOf() method in Java with Examples

TextStyle valueOf() method in Java with Examples

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

Syntax:

public static TextStyle valueOf(String name)

Parameters: This method accepts 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.

Exception: 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 TextStyle.valueOf() method:
Program 1:




// Java program to demonstrate
// TextStyle.valueOf() method
  
import java.time.format.TextStyle;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // get TextStyle
        TextStyle ts
            = TextStyle.valueOf("NARROW_STANDALONE");
  
        // print
        System.out.println("TextStyle: "
                           + ts);
    }
}


Output:

TextStyle: NARROW_STANDALONE

Program 2:




// Java program to demonstrate
// TextStyle.valueOf() method
  
import java.time.format.TextStyle;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // get TextStyle
        TextStyle ts
            = TextStyle.valueOf("SHORT_STANDALONE");
  
        // print
        System.out.println("TextStyle: "
                           + ts);
    }
}


Output:

TextStyle: SHORT_STANDALONE

References: https://docs.oracle.com/javase/10/docs/api/java/time/format/TextStyle.html#valueOf(java.lang.String)

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6898 POSTS0 COMMENTS
Nicole Veronica
12014 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6965 POSTS0 COMMENTS