what is an enum ?

Hello all, I have been reading on enum from many tutorials... but still iam confused what it's real job , what doesnt it mean, what the difference between it and an ARRAY ? Thanks
[202 byte] By [basharfa] at [2007-10-3 0:10:31]
# 1
Hello you.Have you read this? http://java.sun.com/docs/books/tutorial/java/javaOO/enum.htmlAs for the difference with arrays, can you explain why you are comparing enums to arrays? Can you list anything in common between them?
Lokoa at 2007-7-14 17:00:02 > top of Java-index,Java Essentials,Java Programming...
# 2
Enums are basically a fast way to define constants. They are almost as versatile as static classes, and even faster to write than the former constant pattern (public final static int ...).
Mongera at 2007-7-14 17:00:02 > top of Java-index,Java Essentials,Java Programming...
# 3

An enum is a way of defining related constants, e.g. days of the week or months of the year.

enums are better than just using constants as they have a related significance.

For example if you defined the constants JANUARY=1 and MONDAY=1, there would be nothing stopping you setting int dayOfWeek=JANUARY.

If you define the days of the week as enumerations and the months of the year as enumerations, the above situation cannot occur.

david.saltera at 2007-7-14 17:00:02 > top of Java-index,Java Essentials,Java Programming...
# 4

There's a lot of cases in programming where a variable represents some kind of quality that takes on of a finite list of values. Like the state of a traffic light can be only red, amber or green, a business can be open or closed.

You can assign a number to each possible state and use an int. Enums are a more naturalistic representation.

as in:

enum LightState {Red,Amber,Green};

They are frequently used in switch statements, and also there are two important related classes EnumSet and EnumMap. An EnumMap is like an array in which the values are selected according to an enum value, rather than according to an integer.

They are implemented by assigning a numeric value to each value, but you shouldn't code on that basis.

malcolmmca at 2007-7-14 17:00:02 > top of Java-index,Java Essentials,Java Programming...
# 5
with Enums, you can define your own types like int, String,...Besides, you can only give restricted values on enum variable and these values are declared while creating an Enum.
samue-1a at 2007-7-14 17:00:02 > top of Java-index,Java Essentials,Java Programming...