Tuesday, July 16, 2013

Java - loop to iterate over enum

public enum Direction {
   NORTH,
   NORTHEAST,
   EAST,
   SOUTHEAST,
   SOUTH,
   SOUTHWEST,
   WEST,
   NORTHWEST
}

for (Direction dir : Direction.values()) {
  // do what you want
}

Reference:
http://stackoverflow.com/questions/1104975/for-loop-to-iterate-over-enum-in-java

0 comments:

Post a Comment