Which statement will iterate through Direction?
A.
for (Direction d : Direction.values()){
//
}
B.
for (Direction d : Direction.asList()){
//
}
C.
for (Direction d : Direction.iterator()){
//
}
D.
for (Direction d : Direction.asArray()){
//
}
Explanation:
The static values() method of an enum type returns an array of the enum values. The foreach loop
is a good
way to go over all of them.
//… Loop over all values.
for (Direction d : Direction.values()){
System.out.println(d); // PrintsNORTH, EAST, …
}
A