All enumerations automatically contain two predefined methods: values( ) and valueOf( ).
The values( ) method returns an array that contains a list of the enumeration constants.
The valueOf( ) method returns the enumeration constant whose value corresponds to the string passed in str.
enum Week { Monday, Tuesday, Wednesday, Thursday, Friday, Saturaday, Sunday } public class MainClass { public static void main(String args[]) { System.out.println("Here are all Week constants"); // use values() Week allWeek[] = Week.values(); for (Week aday : allWeek) { System.out.println(aday); } } }
Here are all Week constants Monday Tuesday Wednesday Thursday Friday Saturaday Sunday