This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Java in General and the fly likes Enums vs. HashMap vs. others for decision handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Enums vs. HashMap vs. others for decision handling" Watch "Enums vs. HashMap vs. others for decision handling" New topic

Enums vs. HashMap vs. others for decision handling

nithin chinni
Ranch Hand

Joined: Dec 02, 2010
Posts: 41
In my project I have encountered a situation where given an input functionality varies.
So I have though of two ways for dealing with this situation. Both work but want to choose one.
First Method:
Using a Enum where given an input and depending on enum output I will handle the business login. Also I have handled the exception saying if there is no enum for that particular type I will return null.

Second Method:
Using HashMap which gives the value when given a key. And using that value will build the business logic.

There are even many ways like using if-else, switch-case etc.
Can someone help me in choosing why I should go with a particular implementation.
My team lead says hashmaps because of performance but there will not be more than 5 types.
I prefer enums because of the readability.

So thats where I am thinking, what to go with. Any suggestions??
Stephan van Hulst

Joined: Sep 20, 2010
Posts: 4200

This is an incredibly vague description of your problem. Maybe you can give us more background on what it really is that your business logic is about.

The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
It is sorta covered in the JavaRanch Style Guide.
subject: Enums vs. HashMap vs. others for decision handling
It's not a secret anymore!