I want to do something like this:
int[][] A = ... // initialize matrix
List<Integer> rows = new LinkedList<Integer>();
for (int r = 0; r < 1000000; r++) rows.add(r);
Iterator<Integer> iter = rows.iterator();
for ( ; iter.hasNext(); ) {
// some condition based on which I remove an element
if (200 != A[iter.next().intValue()][0]) iter.remove();
}
if (rows.isEmpty()) {
System.out.println("empty");
}
But it does not work.
More than likely you are getting an
ArrayIndexOutOfBoundsException. This is because the valueA[iter.next().intValue()]has exceeded the row bounds set in yourinitialize matrixsection.Assuming you do have rows, you could use: