Monday, July 6, 2026
HomeLanguagesJavaTextStyle values() method in Java with Examples

TextStyle values() method in Java with Examples

The values() method of TextStyle enum is used to an array containing the constants of this enum type, in the order, they are declared.

Syntax:

public static TextStyle[] values()

Parameters: This method accepts nothing.

Return value: This method returns an array containing the constants of this enum type, in the order, they are declared.

Below programs illustrate the TextStyle.values() method:
Program 1:




// Java program to demonstrate
// TextStyle.values() method
  
import java.time.format.TextStyle;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // get TextStyle
        TextStyle ts
            = TextStyle.valueOf("NARROW");
  
        // apply values()
        TextStyle[] array
            = ts.values();
  
        // print
        for (int i = 0; i < array.length; i++)
            System.out.println(array[i]);
    }
}


Output:

FULL
FULL_STANDALONE
SHORT
SHORT_STANDALONE
NARROW
NARROW_STANDALONE

Program 2:




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


Output:

TextStyle length:6

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

RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32519 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6900 POSTS0 COMMENTS
Nicole Veronica
12015 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12110 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7263 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6967 POSTS0 COMMENTS