Ragged and Jagged Arrays

前端 未结 4 1821
情书的邮戳
情书的邮戳 2021-02-07 12:42

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条回答
  •  长发绾君心
    2021-02-07 13:27

    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];
    

提交回复
热议问题