Use the built-in enumeration methods.
enum Direction{ North, South, East, West//from www . ja v a 2 s. c om } public class Main { public static void main(String args[]) { Direction ap = Direction.North; // Output an enum value. System.out.println("Value of ap: " + ap); // use values() Direction all[] = Direction.values(); for(Direction a : all) System.out.println(a); System.out.println(); // use valueOf() ap = Direction.valueOf("East"); System.out.println("ap contains " + ap); } }