How to Print Java Multidimensional Array?

Printing a Multidimensional Array is more like a one-dimensional Array.

Below is the implementation of the above method:

Java




// Java Program for printing
// Java multidimensional array
import java.io.*;
import java.util.*;
  
class GFG {
    public static void main(String[] args)
    {
        int[][] array
            = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
  
        System.out.println(
            "Values of Multi-Dimensional Array:");
        System.out.println(Arrays.deepToString(array));
    }
}


Output

Values of Multi-Dimensional Array:
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]


Java Program to Print the Elements of an Array

An array is a data structure that stores a collection of like-typed variables in contiguous memory allocation. Once created, the size of an array in Java cannot be changed. It’s important to note that arrays in Java function differently than they do in C/C++

As you see, the array of size 9 holds elements including 40, 55, 63, 17, 22, 68, 89, 97, and 89. and each element has its corresponding index value. we can use this index value i.e. array_name[Index_Value] to access the element.

Properties of Java Array

Here are some important points about Java Arrays:

  1. In Java, all arrays are dynamically allocated.
  2. Since arrays are objects in Java, user can find their length using the object property length. This is different from C/C++ where length  is calculated using function sizeof()
  3. A Java array variable can also be declared like other variables with [] after the data type.
  4. The variables in the array are ordered and each has an index beginning from 0.
  5. Java array can be also be used as a static field, a local variable, or a method parameter.
  6. The size of an array must be specified by an int value and not long or short.
  7. The direct superclass of an array type is Object.
  8. Every array type implements the interfaces Cloneable and java.io.Serializable.

Similar Reads

How to Print an Array in Java?

There are two methods to Print an Array in Java as mentioned below:...

How to Print Java Multidimensional Array?

...