I want to store some user preferences Would Enum be a good datastructure to store them? If so, how do I do it? This is the final usage of the datastructure.
main(){
int my_val = PREFERENCES.BLACK;
switch(PREFERENCES){
case BLACK:
...
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Typically, preferences for a program have a variety of data types: Your windows positions are usually integers expressing X,Y positions; default file or directory names may be strings, color values would usually be stored as
java.awt.Colorvalues, and so on.enums would come in handy only for values that take on one of a small number of predefined possibilities, and those possibilities aren’t values that are naturally represented by integers, characters, strings, floats, colors or other more specialized data types. A good use for an enum would be the position of a toolbar:{ TOP, LEFT, BOTTOM, RIGHT, CENTER }or something like that.Enums are their own data type; you don’t store their values in
ints (or you’d be talking aboutfinal intfields and notenums). You create someenumvariables of the type you want, and you can basically only assign one of the type’s fixed values to it. You can then later do aswitchstatement onenumvariables, though.