Best practice Java - String array constant and indexing it
Posted
by
Pramod
on Programmers
See other posts from Programmers
or by Pramod
Published on 2011-11-15T15:28:16Z
Indexed on
2011/11/15
18:07 UTC
Read the original article
Hit count: 284
For string constants its usual to use a class with final String
values. But whats the best practice for storing string array. I want to store different categories in a constant array and everytime a category has been selected, I want to know which category it belongs to and process based on that.
Addition : To make it more clear, I have a categories A,B,C,D,E
which is a constant array. Whenever a user clicks one of the items(button will have those texts) I should know which item was clicked and do processing on that.
I can define an enum
(say cat
) and everytime do
if clickedItem == cat.A
....
else if clickedItem = cat.B
....
else if
....
or even register listeners for each item seperately.
But I wanted to know the best practice for doing handling these kind of problems.
© Programmers or respective owner