Which of the following code snippets declares a jagged array?

  • int jaggedArray[3][];
  • int[3][] jaggedArray;
  • int[] jaggedArray[3];
  • int[][] jaggedArray = new int[3][];
A jagged array is an array of arrays in which the sub-arrays can have different lengths. The correct declaration for a jagged array in Java is option 1, where you specify the number of rows (3) but leave the size of the second dimension unspecified. This allows each sub-array to have a different length.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *