I have a 3D array, I am able to find all the index of all the array elements except one element "null"
i.e. the one after the element "x"
.
我有一个3D数组,我可以找到所有数组元素的索引,除了一个元素“null”,也就是元素“x”后面的元素。
public class StringArrayTest
{
public static void main(String args[])
{
String[][][] arr ={
{
{ "a", "b" , "c"},
{ "d", "e", null }
},
{
{"x"}, null },
{{"y"}
},
{
{ "z","p"},
{}
}
};
System.out.println(arr[0][1][2]);
}
}
The question was taken from a book and the question itself was not indentated properly and it is quite confusing in the 2nd part of the array(the place where element x is).
这个问题是从一本书中提出来的,这个问题本身并没有被正确地描述,而且在数组的第二部分(元素x所在的位置)是相当令人困惑的。
I was able to find the index of the following element :-
我能找到以下元素的索引:-
a:-[0][0][0]
b:-[0][0][1]
c:-[0][0][2]
d:-[0][1][0]
e:-[0][1][1]
null:-[0][1][2]
x:-[1][0][0]
null:-Not able to find
Y:-[2][0][0]
z:-[3][0][0]
p:-[3][0][1]
What is the index value of the 2nd null, and please explain your answer.
第2个空的索引值是多少,请解释你的答案。
2 个解决方案
#1
3
The index of the 2nd null is [1][1]
. It's the second element of the second row.
第二个null的索引是[1][1]。它是第二行的第二个元素。
The first element of the second row is the {"x"}
array, whose index is [1][0]
(the index of the "x" String within that array is [1][0][0]
), and the null
follows directly after it.
第二行的第一个元素是{“x”}数组,其索引为[1][0](该数组中“x”字符串的索引为[1][0][0]),null紧随其后。
arr[1][1]
would return null
.
arr[1][1]将返回null。
As for the table you asked for (I hope I don't have any typos) :
至于你要的桌子(我希望我没有任何拼写错误):
arr[0] => [0] => [0] => "a"
[1] => "b"
[2] => "c"
[1] => [0] => "d"
[1] => "e"
[2] => null
arr[1] => [0] => [0] => "x"
[1] => null
arr[2] => [0] => [0] => "y"
arr[3] => [0] => [0] => "z"
[1] => "p"
[1] => []
#2
1
In java multidimensional arrays are created with nested arrays. An array holding another array, making a two dimensional array. Java's array implementation is different than general. So, the null value you are not able to find have an index (1, 1). This is two dimensional because the third dimensional array is simply a value of two dimensional array and is null.
在java中,多维数组是用嵌套数组创建的。一个包含另一个数组的数组,组成一个二维数组。Java的数组实现与通用的不同。所以你找不到的零值有一个索引(1,1)这是二维的因为三维数组只是二维数组的一个值并且是空的。
#1
3
The index of the 2nd null is [1][1]
. It's the second element of the second row.
第二个null的索引是[1][1]。它是第二行的第二个元素。
The first element of the second row is the {"x"}
array, whose index is [1][0]
(the index of the "x" String within that array is [1][0][0]
), and the null
follows directly after it.
第二行的第一个元素是{“x”}数组,其索引为[1][0](该数组中“x”字符串的索引为[1][0][0]),null紧随其后。
arr[1][1]
would return null
.
arr[1][1]将返回null。
As for the table you asked for (I hope I don't have any typos) :
至于你要的桌子(我希望我没有任何拼写错误):
arr[0] => [0] => [0] => "a"
[1] => "b"
[2] => "c"
[1] => [0] => "d"
[1] => "e"
[2] => null
arr[1] => [0] => [0] => "x"
[1] => null
arr[2] => [0] => [0] => "y"
arr[3] => [0] => [0] => "z"
[1] => "p"
[1] => []
#2
1
In java multidimensional arrays are created with nested arrays. An array holding another array, making a two dimensional array. Java's array implementation is different than general. So, the null value you are not able to find have an index (1, 1). This is two dimensional because the third dimensional array is simply a value of two dimensional array and is null.
在java中,多维数组是用嵌套数组创建的。一个包含另一个数组的数组,组成一个二维数组。Java的数组实现与通用的不同。所以你找不到的零值有一个索引(1,1)这是二维的因为三维数组只是二维数组的一个值并且是空的。