All enums implicitly inherit java.lang.Enum class.

values() is a static method of java.lang.Enum class. Hence, values() method is available in enum classes.

values() method gives an array of enum class values.

values() method can be used to iterate all the enum class values.

e.g. Suppose MONTHS is an enum class containing constants. Then the values can be obtained as below:

MONTHS []val = MONTHS.values();

Demo Example : values() method of java.lang.Enum

The below example explains how to iterate through the constant values of an enum class.

MONTHS.java

package com.masterjavatutorial;
public enum MONTHS {
    JANuARY,FEBRUARY,MARCH,APRIL,
    MAY,JUNE,JULY,AUGUST,
    SEPTEMBER,OCTOBER,NOVEMBER,DECEMBER;

}

Test.java

package com.masterjavatutorial;

public class Test {

	public static void main(String args[]) {

		MONTHS[] values = MONTHS.values();
		for(MONTHS value : values){
			System.out.println(value);
 		}
              
	
	}
}

Output of the above program is as below:

JANuARY
FEBRUARY
MARCH
APRIL
MAY
JUNE
JULY
AUGUST
SEPTEMBER
OCTOBER
NOVEMBER
DECEMBER