I have a class called Bird that is composed of 3 string fields, each of which is the name in a different language, say Bird.lang1, Bird.lang2, Bird.lang3. And I have an instance of Bird called allbirds.
Now I want to make a list of strings ListOfAllBirds with the names of all birds, in the language the user choices, that is stored in the lang variable, whose value is one of lang1, lang2, lang3. And I need to do this hundreds of times (call this number of times N).
Of course, I can do an iterator over all Bird elements, and add the corresponding field to that of lang. But this implies in 3 x N x Bird.size() (that is, hundreds of thousands!!) conditional queries to test the language the user choose.
Can I do something like
varfield = lang.toField();
for (Bird birdy : allbirds)
ListOfAllBirds.add(birdy.varfield);
That is, can I make a reference to a field with a variable?? This would save me tons of conditional queries!
Thanks!
What I meant with using a String array was something like this (if you do not want to change your language setting to an int as Vulcan suggested).
Your class would then look like this:
instead of
This way you only have to check for the language chosen by the user once (to find the index) and you can then iterate through all birds and get the correct name based on the index.