Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ragged and Jagged Arrays

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.

like image 815
Nitesh Verma Avatar asked Aug 16 '13 08:08

Nitesh Verma


People also ask

What are ragged arrays in Java?

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.

What is difference between array and 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.

Why would you use a jagged array?

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.

How do you create a ragged array?

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.


1 Answers

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!

like image 87
Gerret Avatar answered Oct 09 '22 22:10

Gerret