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 3788950
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:04:45+00:00 2026-05-19T12:04:45+00:00

Hi so lately I’ve been doing a lot of java programming and I’ve been

  • 0

Hi so lately I’ve been doing a lot of java programming and I’ve been using a lot of if statements. the problem is i have to copy and paste the if statements over a hundred times to check all the senarios. Here is an example:

while (i < AreaNumbers.size()) {
        String roomnum = "j" + AreaNumbers.get(i);
        if (roomnum.equals("j100")) {
            if (k == 1) {
                j100.setVisible(true);
                j100.setToolTipText("<html>" + "<br>" + "Room Number: " + AreaNumbers.get(i) + "<br>" + "Incident ID: " + IncidentID.get(i) + "<br>" + " Teacher: " + Teachers.get(i) + "<br>" + " Description: " + Descriptions.get(i) + "</html>");
                k = k + 1;
            } else if (k > 0) {
                j100.setToolTipText(k + " help desk calls, click here for more information");
                k = k + 1;
            }

for this example i would copy and paste the if (roomnum.equals("j100")) { and everything past it for every label i want to check and compare. Is there anyway i could do this where i could write a statement that goes through this same scenario once and everywhere it sees j100 it could replace it after each time with a different label, such as j101 j107 an so on. Im sorry if this isnt very clear i just cant think of a better way to word it. Thanks in advance.

  • 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-19T12:04:46+00:00Added an answer on May 19, 2026 at 12:04 pm

    Don’t use numbered variable names (like j100, j101, etc.). Use an array instead, so you can loop over them programatically:

    SomeType[] j = new SomeType[1000];
    
    for (int z = 0; z < j.length; z++) {
        j[z] = new SomeType();
    
        j[z].setTooltipText("Hello world");
    }
    

    Depending on what you need to do, you may want to investigate the more advanced collections classes instead of simple arrays.

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

Sidebar

Related Questions

Lately I have been doing some numerical method programming in C. For the bug
lately I have been writing a lot of tiny plugins for my web projects
Lately I've been using XPathDocument and XNavigator to parse an XML file for a
Lately I have seen a lot of blog posts concerning how to build loosely
Lately all modern programming languages have a definitive web site to support, distribute, learn
Lately I have been working with predictive analytics and in many cases my PC
Lately I have been thinking about developing some basic android app. Its only due
Lately I have been interested in better understanding the optimizations done by compiler back-ends.
Lately, I have seen a lot of questions being asked about output for some
Lately I have been finding that some of the ColdFusion applications on my production

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.