14

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.

4
  • 5
    As far as I know, it's just two names for the same thing.
    – Jsdodgers
    Aug 16, 2013 at 8:39
  • 2
    They mean the same thing.
    – Kon
    Aug 16, 2013 at 8:39
  • All right, any reason why different names, could it be programming language specific? Aug 16, 2013 at 8:41
  • 1
    The only problem with your definition is that ragged/jagged arrays can have more than 2 dimensions.
    – Stephen C
    Aug 16, 2013 at 9:16

4 Answers 4

19

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!

2
  • Thanks for the clarification. Aug 16, 2013 at 9:14
  • could you care to share any links where I can read more about them? Aug 16, 2013 at 9:16
0

Jagged array is array of arrays such that member arrays can be of different sizes, i.e., we can create a 2-D arrays but with variable number of columns in each row. These type of arrays are also known as ragged arrays.

Contents of 2D Jagged Array
0 
1 2 
3 4 5 
6 7 8 9 
10 11 12 13 14 

http://www.geeksforgeeks.org/jagged-array-in-java/

0

Ragged Array is also known as Jagged Array

1- A jagged array is non uniform array

2- Inner arrays can't be initialized so the following code snippet is going to fail

   double[][] jagged = new double[2][3]; //error

3- Instead each inner array is initialized separately

   double[][] jagged = new double[2][];
   jagged[0] = new double[5];
   jagged[1] = new double[7];
1
  • double[][] jagged = new double[2][3]; is valid Java, isn't it? Do you mean that it's an "error" only in that it isn't a ragged array?
    – mic
    Feb 20, 2021 at 21:33
-2

Ragged array: is an array with more than one dimension each dimension has different size

ex:

10 20 30
11 22 22 33 44
77 88

Jagged array: an array where each item in the array is another array. C# Code:

int[][] jaggedArray = new int[3][];
jaggedArray[0] = new int[5];
jaggedArray[1] = new int[4];
jaggedArray[2] = new int[2];
2
  • 1
    that is not really a difference?
    – Matthias G
    Aug 16, 2013 at 8:43
  • Then what is the actual difference. Aug 16, 2013 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.