I\'ve heard of using a two dimensional array like this :
String[][] strArr;
But is there any way of doing this with a list?
Maybe s
Declaring a two dimensional ArrayList:
ArrayList> rows = new ArrayList();
Or
ArrayList> rows = new ArrayList<>();
Or
ArrayList> rows = new ArrayList>();
All the above are valid declarations for a two dimensional ArrayList!
Now, Declaring a one dimensional ArrayList:
ArrayList row = new ArrayList<>();
Inserting values in the two dimensional ArrayList:
for(int i=0; i<5; i++){
ArrayList row = new ArrayList<>();
for(int j=0; j<5; j++){
row.add("Add values here");
}
rows.add(row);
}
fetching the values from the two dimensional ArrayList:
for(int i=0; i<5; i++){
for(int j=0; j<5; j++){
System.out.print(rows.get(i).get(j)+" ");
}
System.out.println("");
}