Print 2D list java
This post will discuss how to print a two-dimensional array in Java. In the previous post, we have discussed how to declare and initialize two-dimensional arrays in Java. This post will discuss how to print them. 1. Using Arrays.toString() methodWe know that a two-dimensional array in Java is a single-dimensional array having another single-dimensional array as its elements. We can use the Arrays.toString() method to print string representation of each single-dimensional array in the given two-dimensional array.
DownloadRun Code Output:
2. Using Inner for-loopA naive solution would use two loops the outer loop for the first dimension and the inner loop for the second dimension of the two-dimensional array.
DownloadRun Code Output: 8 9
Thats all about printing two-dimensional arrays in Java. |