Alex Rivera | Logout

When to use Enum or Collection in Java

Asked 2009-01-26T19:45:30.743
24

Under what circumstances is an enum more appropriate than, for example, a Collection that guarantees unique elements (an implementer of java.util.Set, I guess...)?

(This is kind of a follow up from my previous question)

Edit
Report

1 Answer

3

I am no java guru, but my guess is to use enumeration when you want to gurantee a certain pool of values, and to use a collection when you want to gurantee uniqueness. Example would be to enumerate days of the week (cant have "funday") and to have a collection of SSN (generic example i know!)

answered 2009-01-26T19:48:28.117

Your Answer