How can I put a Java arrays inside an array?


Example

Live Demo

import java.util.Arrays;

public class ArrayWithinAnArray{
   public static void main(String args[]) {
      int[] myArray1 = {23, 56, 78, 91};
      int[] myArray2 = {123, 156, 178, 191};
      int[] myArray3 = {223, 256, 278, 291};
      int[] myArray4 = {323, 356, 378, 391};
      int [][] arrayOfArrays = {myArray1, myArray2, myArray3, myArray4};
      System.out.println(Arrays.deepToString(arrayOfArrays));
   }
}

Output

[[23, 56, 78, 91], [123, 156, 178, 191], [223, 256, 278, 291], [323, 356, 378, 391]]

Updated on: 16-Jun-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements