Enum: values()
/*
Here are all Apple constants
A
B
C
D
E
ap contains C
*/
enum Apple {
A, B, C, D, E
}
public class MainClass {
public static void main(String args[])
{
Apple ap;
System.out.println("Here are all Apple constants");
Apple allapples[] = Apple.values();
for(Apple a : allapples)
System.out.println(a);
System.out.println();
ap = Apple.valueOf("C");
System.out.println("ap contains " + ap);
}
}
Related examples in the same category