import java.util.*;
public class arrayIterator {
public static void main(String[] args) {
int ar[][] = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 },
{ 13, 14, 15, 16 } };
ArrayList list[] = { new ArrayList(), new ArrayList(), new ArrayList(),
new ArrayList() };
for (int i = 0; i <= 3; i++) {
for (int j = 0; j <= 3; j++) {
list[i].add(ar[i][j]);
}
}
Iterator it[] = { list[0].iterator(), list[1].iterator(),
list[2].iterator(), list[3].iterator() };
for (int k = 0; k <= 3; k++) {
while (it[k].hasNext()) {
System.out.print(it[k].next() + "\t");
}
System.out.println();
}
}
}
Output :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.