Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8958857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:18:45+00:00 2026-06-15T15:18:45+00:00

I have a class called Bird that is composed of 3 string fields, each

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:18:47+00:00Added an answer on June 15, 2026 at 3:18 pm

    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).

    String chosenLanguage = "Language 2";
    int languageIndex = -1;
    switch(chosenLanguage)
    {
        case "Language 1": 
            languageIndex = 0;
            break;
        case "Language 2":
            languageIndex = 1;
            break;
        case "Language 3":
            languageIndex = 2;
            break;
        default:
            languageIndex = 0;
            break;
    }
    
    for (Bird birdy : allbirds)
           ListOfAllBirds.add(birdy.names[languageIndex]);
    

    Your class would then look like this:

    class Bird
    {
        public String[] names = {"name1", "name2", "name3"};
    }
    

    instead of

    class Bird
    {
        public String lang1 = "name1";
        public String lang2 = "name2";
        public String lang3 = "name3";
    }
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class called: ComplexNumber and I have a string that I need
I have a class called Flamethrower which naturally has its own ammunition that is
I have this class called Table: class Table { public string Name { get
I have class called GroupItem, i can store any type here say int, string,
I have a class called ElementInfo public class ElementInfo { public String name; public
I have a class called Trial which has_many results. Now What I want to
I have a class called Metadata, which is declared within the namespace A::B::C ,
I have a class called Property which has nothing but get -methods. All the
I have one class called Global and two other activities. In each activity I
I have a class called Property that I only need to display a few

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.