简体   繁体   English

为什么每个的左侧尺寸不等于右侧?

[英]Why the left side size in for each is not equal to the right side?

The declared size in for-each is always less than the size of the array.why ? for-each声明的大小总是小于数组的大小。为什么?

int[][][] c = {{{1,2,3}}};
for(int [][] z : c )
    //code

c is a 3D array so should z, right? c 是一个 3D 数组,所以 z 应该是,对吗? like:喜欢:

int[][][] c = {{{1,2,3}}};
for (int[][][] z : c) // which is syntactically wrong
    //code

Thank you in advance.先感谢您。

The answer as I understand it from the comments and the below answer: the declaration inside for-each我从评论和以下答案中理解的答案: for-each内部的声明

in the 3D array for-each considers every 2D array as an element,在 3D 数组中for-each将每个 2D 数组视为一个元素,

in the 2D array for-each considers every 1D array as an element and so on..在二维数组中for-each将每个一维数组视为一个元素,依此类推。

in the 1D array it takes the elements of the array directly as elements.在一维数组中,它直接将数组的元素作为元素。

Read that construct as the for-each loop.将该构造读作for-each循环。 In this case, for each int[][] in the int[][][] .在这种情况下,对于int[][]中的每个int[][] int[][][] Another example, for-each int in an int[] .另一个例子, for-each int in an int[]

int[] arr = {1,2,3};
for (int i : arr) {
    System.out.println(i);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当文本太长时,为什么我的JTextfield文本在左侧而不是右侧? - Why is my JTextfield text going over the left side instead of the right when text is too long for size? 检查数组左侧的总和是否等于 o(n) 中数组的右侧 - Check if sum of left side of array equal to right side of array in o(n) 如何创建一个界面,显示左侧的对象和右侧每个对象的详细信息? - How to create an interface which shows the objects in left side and detail for each object in the right side? Java Regex的低位字母下划线,左下划线,中间等于下划线,右下划线 - Java Regex with low letters underscore left, equal middle and any at right side Java 右侧小于等于的语句 - Java statement with less than equal to on the right side 禁用ViewPager从右向左和从左向右滑动 - Disable ViewPager Swipe From Right To Left and Left To Right Side JSP中的页眉,页脚,左侧和右侧模板 - Header, Footer, Left and Right side Template in JSP 格式化双精度数,左侧和右侧为零 - format double with zeros on left and right side 赋值语句左侧的Java后缀增量运算符的语义是什么,为什么它们与右侧不同? - What are the semantics of java's postfix increment operator on the left side of an assignment statement and why do they differ from the right side? ListView JavaFX中交替行左侧和右侧的图像和文本 - Image & text in left and right side on alternate row in ListView JavaFX
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM