Thursday, December 18, 2025
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

Most Popular

Dominic
32455 POSTS0 COMMENTS
Milvus
108 POSTS0 COMMENTS
Nango Kala
6823 POSTS0 COMMENTS
Nicole Veronica
11958 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12035 POSTS0 COMMENTS
Shaida Kate Naidoo
6958 POSTS0 COMMENTS
Ted Musemwa
7203 POSTS0 COMMENTS
Thapelo Manthata
6910 POSTS0 COMMENTS
Umr Jansen
6890 POSTS0 COMMENTS