2017-01-20 58 views
-2
List<int[][]> matrices = new ArrayList<>(); 

我的arraylist是這樣的。我想打印存儲到arrayList中的二維數組中的所有元素。我怎樣才能做到這一點 ?如何打印Arraylist中的二維整數陣列

我試過一些解決方案here但這些都不適合我。

+0

您是否嘗試過的東西?在這裏顯示。 – AxelH

+0

Duplicate http://stackoverflow.com/questions/32376276/print-values-of-a-2d-arraylist-matrix – Uzair

回答

1

迭代列表,並使用Arrays.deepToString打印每一個元素:

matrices.stream() 
    .map(Arrays::deepToString) 
    .forEach(System.out::println); 

或者,對Java的版本不支持流:

for (int[][] matrix : matrices) { 
    System.out.println(Arrays.deepToString(matrix)); 
} 
+0

非常感謝。這是行得通的。 –