-2
  List<int[][]> matrices = new ArrayList<>();

my arraylist is this. I wanna print all the elements in 2-d arrays which store into the arrayList. How can I do this ?

I tried some solutions here but these are not working for me.

Community
  • 1
  • 1
Büşra GÜL
  • 323
  • 1
  • 4
  • 16

1 Answers1

1

Iterate the list, and use Arrays.deepToString to print each element:

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

Or, for versions of Java which don't support streams:

for (int[][] matrix : matrices) {
  System.out.println(Arrays.deepToString(matrix));
}
Andy Turner
  • 137,514
  • 11
  • 162
  • 243