This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Question about Java constants and enums Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question about Java constants and enums" Watch "Question about Java constants and enums" New topic
Author

Question about Java constants and enums

Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
Is there a more elegant way to make static final Strings?

I have a whole list of user options as Strings and I am keeping them as constants so that if at a later date I want to change an option I can do it in one place. I know that enums are great for ints and stuff like that, but right now I have a long list of static final Strings and a big line of if then else statements checking the user input against the available Strings.

Any options to make the code cleaner?

Thanks!


SCJA
~Currently preparing for SCJP6
BV Boose
Ranch Hand

Joined: Jul 26, 2008
Posts: 33
do you have an example of what these choices look like? Can they be broken down into categories? or will every user input result in a unique response? What about .property or .xml files? You can use enums for more then just ints.
http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question about Java constants and enums
 
Similar Threads
Enum Type inhteritance
Enums
when to use Enum
abstract class(all abstract methods) vs interface
enum question