- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Dump Multi-Dimensional arrays in Java
A multi-dimensional array can be easily printed by using the method java.util.Arrays.deepToString() in Java. This method converts the multi-dimensional array to string and prints the array contents enclosed in square brackets.
A program that demonstrates this is given as follows −
Example
import java.util.Arrays; public class Demo { public static void main(String args[]) { int arr [][]= { {5, 8, 6, 3}, {1, 9, 7}, {4, 8, 2}, {6} }; System.out.println("The multi-dimensional array content is:"); System.out.println(Arrays.deepToString(arr)); } }
Output
The multi-dimensional array content is: [[5, 8, 6, 3], [1, 9, 7], [4, 8, 2], [6]]
Now let us understand the above program.
The multi-dimensional array arr[][] is defined. Then the array content is printed using the Arrays.DeepToString() method. A code snippet which demonstrates this is as follows −
int arr [][]= { {5, 8, 6, 3}, {1, 9, 7}, {4, 8, 2}, {6} }; System.out.println("The multi-dimentional array content is:"); System.out.println(Arrays.deepToString(arr));
Advertisements