Wednesday, February 25, 2026
HomeLanguagesJavaTimeUnit values() method in Java with Examples

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:




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


Output:

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

1 COMMENT

Most Popular

Dominic
32506 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6882 POSTS0 COMMENTS
Nicole Veronica
12005 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12099 POSTS0 COMMENTS
Shaida Kate Naidoo
7011 POSTS0 COMMENTS
Ted Musemwa
7255 POSTS0 COMMENTS
Thapelo Manthata
6967 POSTS0 COMMENTS
Umr Jansen
6956 POSTS0 COMMENTS