Java Program to Access All the Constant Defined in the Enum Last Updated : 22 Feb, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report An enum is a special class that represents a group of constants. To create an enum, use the enum keyword (instead of class or interface), and separate the constants with a comma. enum Day{ SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY; } values() method can be used to return all values present inside enum. We can't see this method in Javadoc because the compiler adds it. The compiler automatically adds some special methods when it creates an enum. For example, they have a static values method that returns an array containing all the enum's values in the order they are declared. So the values() function list all values of the enumeration. Day days[] = Day.values(); for(Day d : days) System.out.print(d); Java // Java program to show the usage of // values() method of java enumeration enum Day{ SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY; } class Main{ public static void main(String args[]) { // Calling values() Day days[] = Day.values(); for(Day d : days) System.out.println( d ); } } OutputSUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY Comment More infoAdvertise with us Next Article Java Program to Define Ordinal() Method Using Enum Concept K kapilnama1998 Follow Improve Article Tags : Java Java Programs Java-Enumeration Practice Tags : Java Similar Reads Java Program to Convert Enum to String Given an enum containing a group of constants, the task is to convert the enum to a String. Methods: We can solve this problem using two methods: Using name() MethodUsing toString() Method Let us discuss both of them in detail and implementing them to get a better understanding of the same. Method 1 2 min read Java Program to Create ArrayList From Enumeration Enumerations serve the purpose of representing a group of named constants in a programming language. Enums are used when we know all possible values at compile-time, such as choices on a menu, rounding modes, command-line flags, etc. It is not necessary that the set of constants in an enum type stay 2 min read Java Program to Define Ordinal() Method Using Enum Concept Java enum, also called Java enumeration type, is a type whose fields consist of a fixed set of constants. The java.lang.Enum.ordinal() tells about the ordinal number(it is the position in its enum declaration, where the initial constant is assigned an ordinal of zero) for the particular enum. ordina 2 min read How to Implement a Strategy Pattern using Enum in Java? The strategy design pattern is intended to provide a way to choose from a variety of interchangeable strategies. Classic implementation includes an architecture to be implemented by each technique and offers a concrete implementation for execution. The method is chosen from an interface reference, a 2 min read How to get the value of System Property and Environment Variable in Java? How to get the value of Environment variables? The System class in Java provides a method named System.getenv() which can be used to get the value of an environment variable set in the current system. Syntax: public static String getenv(String key); where key is the Environment variable whose values 3 min read EnumMap clear() Method in Java with Examples The Java.util.EnumMap.clear() method in Java is used to remove all the mappings from the map. The method does not delete the map instead it just clears the map of the mappings. Syntax: enum_map.clear() Parameters: This method does not accept any argument. Return Values: This method does not return a 2 min read Like