Tuesday, January 7, 2025
HomeProgrammingSimplest Way to Print a Java Array

Simplest Way to Print a Java Array

The simplest way to print a Java array is by using Arrays.toString() for single-dimensional arrays or Arrays.deepToString() for multi-dimensional arrays.

java
import java.util.Arrays;

int[] arr = {1, 2, 3};
System.out.println(Arrays.toString(arr));

// For multi-dimensional arrays:
int[][] multiArr = {{1, 2}, {3, 4}};
System.out.println(Arrays.deepToString(multiArr));

This outputs the array in a readable format.

RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x