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
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: