且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

循环遍历数组中的元素

更新时间:2023-10-30 22:25:40

Java中的数组从 0 索引到 length - 1 ,不是 1 长度,因此你应该相应地分配你的变量并使用正确的比较运算符。

Arrays in Java are indexed from 0 to length - 1, not 1 to length, therefore you should be assign your variable accordingly and use the correct comparison operator.

你的循环应如下所示:

for(int counter=myArray.length - 1; counter >= 0;counter--){