I've searched for information on how to print the matrices contained in a ArrayList
. But I can not find it.
You will have to obtain each of the matrices of your ArrayList<String[][]>
in each route of your loop , and go through another loop of each of the arrays contained in the matrix, and the same for each String of each array .
for (String[][] matriz : listaEstadosHijos) {
for (String[] array : matriz) {
for (String str : array) {
System.out.print(str + " ");
}
System.out.println("");
}
System.out.println("");
}
I'll give you an example:
public class RecorrerBiDimensional {
public static void main(String[] args) {
String[][] matriz1 = {
{"Diego", "Pedro", "Fernando"},
{"Ana", "Luis", "Antonio"},
{"Sonia", "Federico", "Bartolo", "Africa"}
};
String[][] matriz2 = {
{"Eva", "Lucia", "Cristiano"},
{"Messi", "Isco", "Tico", "Lopetegui"},
{"Luna", "Amelia", "Bale", "Sol"}
};
List<String[][]> listaEstadosHijos = new ArrayList<>();
//añadimos cada una de las matrices a nuestra lista.
listaEstadosHijos.add(matriz1);
listaEstadosHijos.add(matriz2);
//Recorremos cada una de las matrices e imprimimos resultado
for (String[][] matriz : listaEstadosHijos) {
for (String[] array : matriz) {
for (String str : array) {
System.out.print(str + " ");
}
System.out.println("");
}
System.out.println("");
}
}
}
Result:
Diego Pedro Fernando
Ana Luis Antonio
Sonia Federico Bartolo Africa
Eva Lucia Cristiano
Messi Isco Tico Lopetegui
Luna Amelia Bale Sol