I have an enum in Java for the cardinal and intermediate directions:
public enum Direction {
NORTH,
NORTHEAST,
EAST,
SOUTHEAST,
SOUTH,
SOUTHWEST,
WEST,
NORTHWEST
}
How can I write a for loop that iterates through each of these enum values?
.values()You can call the
values()method on your enum.This
values()method is implicitly declared by the compiler. So it is not listed onEnumdoc.