Tuesday, June 9, 2026
HomeLanguagesJavaFormatStyle values() method in Java with Examples

FormatStyle values() method in Java with Examples

The values() method of FormatStyle enum is used to an array containing the units of this FormatStyle, in the order, they are declared.
Syntax: 
 

public static FormatStyle[] 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 FormatStyle.values() method: 
Program 1: 
 

Java




// Java program to demonstrate
// FormatStyle.values() method
 
import java.time.format.FormatStyle;
 
public class GFG {
    public static void main(String[] args)
    {
 
        // Get FormatStyle instance
        FormatStyle formatStyle
            = FormatStyle.valueOf("FULL");
 
        // Get the constants using values()
        FormatStyle[] array
            = formatStyle.values();
 
        // Print the values
        for (int i = 0; i < array.length; i++)
            System.out.println(array[i]);
    }
}


Output: 

FULL
LONG
MEDIUM
SHORT

 

Program 2: 
 

Java




// Java program to demonstrate
// FormatStyle.values() method
 
import java.time.format.FormatStyle;
 
public class GFG {
    public static void main(String[] args)
    {
 
        // Get FormatStyle instance
        FormatStyle formatStyle
            = FormatStyle.valueOf("FULL");
 
        // Get the constants using values()
        FormatStyle[] array
            = formatStyle.values();
 
        // Print the values
        System.out.println("FormatStyle length: "
                           + array.length);
    }
}


Output: 

FormatStyle length: 4

 

References: https://docs.oracle.com/javase/10/docs/api/java/time/format/FormatStyle.html
 

RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6896 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7018 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS