What is the difference between ragged and jagged arrays? As per my research both have the same definitions, i.e. two-dimensional arrays with different column lengths.
Jagged array is a multidimensional array where member arrays are of different size. For example, we can create a 2D array where first array is of 3 elements, and is of 4 elements. Following is the example demonstrating the concept of jagged array.
In a multidimensional array, each element in each dimension has the same, fixed size as the other elements in that dimension. In a jagged array, which is an array of arrays, each inner array can be of a different size.
Jagged arrays are a special type of arrays that can be used to store rows of data of varying lengths to improve performance when working with multi-dimensional arrays.
While creating an array of arrays you only specify the first dimension that represents a number of rows in the array. You can create a two-dimensional jagged array as follows: int myarray[][] = new int[3][]; In the above declaration, a two-dimensional array is declared with three rows.
Your question already says the correct answer ^^ but for completeness.
A Jagged or also called Ragged array is a n-dimensional array that need not the be reactangular means:
int[][] array = {{3, 4, 5}, {77, 50}};
For more examples you could look here and here!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With