Yes. The Java Language Specification for Enums states:
/**
* Returns an array containing the constants of this enum
* type, in the order they're declared. This method may be
* used to iterate over the constants as follows:
*
* for(E c : E.values())
* System.out.println(c);
*
* @return an array containing the constants of this enum
* type, in the order they're declared
*/
public static E[] values();
It will returned an array with the constants as they are declared.
Regarding the Arrays.asList()
method, you can rely on its order as well:
Returns a fixed-size list backed by the specified array. (Changes to the returned list "write through" to the array.)
Consider the below example, which is a very common way to initialize a List
:
List<String> stooges = Arrays.asList("Larry", "Moe", "Curly");
The order of the list will be the same as in the array.