5
When trying to run the section below:
int[] vetor = {1, 2, 3, 4, 5, 6};
System.out.println(Arrays.toString(vetor));
The array is normally displayed as [1, 2, 3, 4, 5, 6]
but if I try with a two-dimensional array, as the section below:
int[][] matriz = {{1, 2, 3, 4, 5, 6}, {8, 10, 12, 14}};
System.out.println(Arrays.toString(matriz));
The result is [[I@7852e922, [I@4e25154f]
and array values are not displayed.
Is there any way to display a direct two-dimensional array on System.out.println
without having to loop or overwrite methods, as occurred in code with the simple array?
The answer is valid and now it is even more complete (I have already left my vote), but regarding the need for tie, the question I addressed as to it is precisely that we do not have to write it, if the method makes the tie internally, as a native feature of language, you didn’t need to write it "in hand".
– user28595
Understood @diegofm, neither of the two ways, need to write the
for
orforeach
in the hand are methods (one with the very suggestive name) that internally is nothing more than a loop. When I was asked I wanted to pass this information in simple form so that everyone understands that we often look for some code and nothing more than to do it in a simple way. Thank you for the comment.– novic