How to print a java array

Since Java 5 you can use Arrays.toString(arr) or Arrays.deepToString(arr) for arrays within arrays. Note that the Object[] version calls .toString() on each object in the array. The output is even decorated in the exact way you’re asking.

Java 8 – Stream.forEach

Output:

Printing simple array

Printing multidimensional  array

Output:

Printing double Array

Output:

int Array

Output:

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.