unheroic-sam
unheroic-sam

Reputation: 7

Print out int[][] array using streams

I have a method rotateImage that returns an int[][] array, I am having trouble understaing how to display the actual values of the array instead of just the hashcode:

[I@548c4f57
[I@1218025c
[I@816f27d

I tried doing this:

Arrays.stream(rotateImage(matrix)).forEach(System.out::println);

but that only returns the hashcode, not the actual numbers themselves. I also tried using to Arrays.toString() method in several ways but always get an error.

Upvotes: -1

Views: 110

Answers (1)

Simon He
Simon He

Reputation: 106

It's cause you're accessing the address and not the actual values. You can simply do a lambda function and iterate through each row

Arrays.stream(rotateImage(matrix)).
         forEach(row -> {
             for(int i : row) {
                System.out.println(i);                 
             }
        });

Upvotes: 0

Related Questions