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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:51:54+00:00 2026-06-18T09:51:54+00:00

I must work with a 2d array. The maximum length of the row slots

  • 0

I must work with a 2d array. The maximum length of the row slots in the array is 100. More often than not, anywhere from 5-20 of these array slots will be filled and not more, however, I must build my code to a max of 100 rows. My question is, is there a way to iterate through only the array slots that have been set, stopping before the last unset, null slots?

//initialize array
String[][] variables = new String[numVariables][100];

//System.out.printf("%s \n", numVariables);

for(int i=0; i < numVariables; i++){
    //reads in variable line
    String variableLine = fin.nextLine();

    //turn variable line into array
    varArray = variableLine.split(" ");

    numRules = Integer.parseInt(varArray[0].replaceAll("\\s",""));

    for(int j=0; j < numRules+1; j++){
        variables[i][j] = varArray[j+1];

        System.out.printf("%s ", variables[i][j]);
    }
    System.out.println("\n");
}

//**LATER IN MY CODE ****//
//ITERATE THROUGH 'variables' array and PRINT OUT ONLY VALUES THAT ARE SET
  • 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-18T09:51:55+00:00Added an answer on June 18, 2026 at 9:51 am

    If you populate the array in order from 0 to 100. If the first 51 elements are populated with the string then you could use:

        for(int i=0; i < numVariables; i++){
            for(int j=0; j < numRules+1; j++){
                if (variables[i][j] == null)
                    break;
                System.out.printf("%s ", variables[i][j]);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

findParent() function find array. There could be one array or more than one. Now
I have thi next code, but he doesn't work: $select_sell = $this->select(); $select_sell->from($this->_name, array('rank_id'))
I have a python program that must work on Windows and Linux. There are
I am working on a project with a library and I must work with
According to this question in order for Flymake to work you must add a
What I must do to make Server.MapPath work? I have using System.Web; what else?
I currently work in an environment where reports must be emailed to users as
Event-delegation must be used to make events work after inserting DOM elements (i.e Ajax
I must be missing something obvious about how the various Scanner methods work but
I need to work with large files and must find differences between two. And

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.