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

  • SEARCH
  • Home
  • 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 711397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:43:50+00:00 2026-05-14T04:43:50+00:00

String [] A = {High,Medium,Low}; String [] B = {High,Medium,Low}; String [] C =

  • 0
String [] A = {"High","Medium","Low"};
String [] B = {"High","Medium","Low"};
String [] C = {"High","Medium","Low"};
String [] D = {"High","Medium","Low"};
String [] E = {"High","Medium","Low"};
String [] F = {"High","Medium","Low"};

JComboBox Ai = new JComboBox(A); JComboBox Bi = new JComboBox(B);
JComboBox Ci = new JComboBox(C); JComboBox Di = new JComboBox(C);
JComboBox Ei = new JComboBox(E); JComboBox Fi = new JComboBox(F);

....

//add the user choice in arrayList
ArrayList<String> a = new ArrayList<String>();
a.add((String) Ai.getSelectedItem());
a.add((String) Bi.getSelectedItem());
a.add((String) Ci.getSelectedItem());
a.add((String) Di.getSelectedItem());
a.add((String) Ei.getSelectedItem());
a.add((String) Fi.getSelectedItem());

EDITED:
Scenario:
There are 6 groups (Ai,Bi,Ci,Di,Ei,Fi) of choice. On each group, there are 3 sub choice (High(H),Medium(M),Low(L)).The user need to choose one on each of the 6 groups

The choice could be e.g. “HHHLLL” or “MMMLLM” or “HHLLMM” etc.

What is the best way to check and match the user choice without writing many else if ?
e.g.

if(Ai=="High" && Bi=="High" && Ci=="Low" && Di=="High" && Ei=="Low" && Fi=="Medium") {
    System.out.println("Good Choice"); 
}

Thank you.

  • 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-05-14T04:43:50+00:00Added an answer on May 14, 2026 at 4:43 am

    First off, you don’t need to give a new list of choices to each JComboBox.

    String[] choices = {"High", "Medium", "Low"};
    
    JComboBox ai = new JComboBox(choices);
    JComboBox bi = new JComboBox(choices);
    JComboBox ci = new JComboBox(choices);
    JComboBox di = new JComboBox(choices);
    JComboBox ei = new JComboBox(choices);
    JComboBox fi = new JComboBox(choices);
    

    (Variables in Java usually start with a lowercase letter, so I changed the variable names to lowercase.)


    Next, you can put all six JComboBoxes in an array. You’ll see why this is useful in a moment.

    JComboBox[] boxes = {ai, bi, ci, di, ei, fi};
    

    Now, you can make your user choice string like this:

    // Create an ArrayList of Strings, where each string is either "H", "M", or "L"
    ArrayList<String> userChoice = new ArrayList<String>()
    
    for (JComboBox box : boxes) {
        // Go through this code once for each JComboBox in boxes
        // The first time through, "box" means the first JComboBox
        // The second time through, "box" is the second JComboBox, etc.
        if (box.getValue().equals("High")) {
             userChoice.add("H");
        } else if (box.getValue().equals("Medium")) {
             userChoice.add("M");
        } else if (box.getValue().equals("Low")) {
             userChoice.add("L")
        }
    }
    

    That for-each loop might not be familiar to you. It means “go through this code once for each something in array of somethings.”


    If you use this code, you’ll end up with an ArrayList called userChoice that has something like [“H”, “H”, “M”, “M”, “L”, “L”].

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

Sidebar

Ask A Question

Stats

  • Questions 456k
  • Answers 456k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I solved this myself by writing my own module that… May 15, 2026 at 10:32 pm
  • Editorial Team
    Editorial Team added an answer This is called Autoboxing which is a feature that was… May 15, 2026 at 10:32 pm
  • Editorial Team
    Editorial Team added an answer There is no such thing as "the best SCM". By… May 15, 2026 at 10:32 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.