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:



filter_none

edit
close

play_arrow

link
brightness_4
code

// 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]);
    }
}

chevron_right


Output:

FULL
FULL_STANDALONE
SHORT
SHORT_STANDALONE
NARROW
NARROW_STANDALONE

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


Output:

TextStyle length:6

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

Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.