Java 参差不齐和参差不齐的阵列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18269123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 23:54:08  来源:igfitidea点击:

Ragged and Jagged Arrays

javaarraysjagged-arrays

提问by Nitesh Verma

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.

参差不齐的阵列和参差不齐的阵列有什么区别?根据我的研究,两者都有相同的定义,即具有不同列长度的二维数组。

采纳答案by Gerret

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:

锯齿状或也称为 Ragged 数组是一个 n 维数组,不需要是 reactangular 手段:

int[][] array = {{3, 4, 5}, {77, 50}};

For more examples you could look hereand here!

有关更多示例,您可以查看这里这里

回答by Bhupendra Shukla

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:

锯齿状数组:数组中的每一项都是另一个数组。C# 代码:

int[][] jaggedArray = new int[3][];
jaggedArray[0] = new int[5];
jaggedArray[1] = new int[4];
jaggedArray[2] = new int[2];

回答by roottraveller

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/

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

回答by Sameh

Ragged Array is also known as Jagged Array

锯齿状阵列也称为锯齿状阵列

1- A jagged array is non uniform array

1- 锯齿状数组是非均匀数组

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

2- 无法初始化内部数组,因此以下代码片段将失败

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

3- Instead each inner array is initialized separately

3- 而是分别初始化每个内部数组

   double[][] jagged = new double[2][];
   jagged[0] = new double[5];
   jagged[1] = new double[7];