TimeUnit values() method in Java with Examples

The values() method of TimeUnit Class returns an array containing the constants of this enum type, in the order they are declared. In short, this method is used to get the Enum Constants of TimeUnit Class.

Syntax:

public static TimeUnit[] values()

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

Below program illustrate the TimeUnit values() method:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// values() method of TimeUnit Class
  
import java.util.concurrent.*;
  
class GFG {
    public static void main(String args[])
    {
  
        System.out.println("The Enum constants "
                           + "of TimeUnit Class "
                           + "using TimeUnit.values() "
                           + "are:");
  
        // Get the array of Enum constants
        // using TimeUnit.values
        // and Iterate over them
        for (TimeUnit constants : TimeUnit.values()) {
            System.out.println(constants);
        }
    }
}

chevron_right


Output:

The Enum constants of TimeUnit Class using TimeUnit.values() are:
NANOSECONDS
MICROSECONDS
MILLISECONDS
SECONDS
MINUTES
HOURS
DAYS


My Personal Notes arrow_drop_up

Technical Content Engineer at GeeksForGeeks

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.