How can I put a Java arrays inside an array?

Java 8Object Oriented ProgrammingProgramming

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]]
raja
Published on 09-Jan-2018 12:30:07
Advertisements