This commit is contained in:
2025-06-12 11:59:41 +02:00
parent f42c1b23ab
commit 57aae3eda6
9 changed files with 354 additions and 12 deletions

View File

@@ -0,0 +1,38 @@
package iterator;
import java.util.Iterator;
import java.util.NoSuchElementException;
public class Array2dIterator<T> implements Iterator<T> {
private T[][] array;
private int row = 0;
private int col = 0;
public Array2dIterator(T[][] array) {
this.array = array;
}
@Override
public boolean hasNext() {
if (row < array.length) {
if (col >= array[row].length) {
col = 0;
row++;
}
}
if (row < array.length && col < array[row].length) {
return true;
}
return false;
}
@Override
public T next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
return array[row][col++];
}
}