Thursday, September 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
32299 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6663 POSTS0 COMMENTS
Nicole Veronica
11835 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11895 POSTS0 COMMENTS
Shaida Kate Naidoo
6779 POSTS0 COMMENTS
Ted Musemwa
7053 POSTS0 COMMENTS
Thapelo Manthata
6736 POSTS0 COMMENTS
Umr Jansen
6742 POSTS0 COMMENTS