我有一个名为e的数组,该数组包含对象,但不包含在每个索引中。所以我使用for-loop来查找包含对象的数组中的第一个索引。我通过查找不为null的值来实现此目的。如果我找到它,我将索引保存在一个名为index的变量中,并跳出循环。如果没有找到没有空值的索引,我想从方法返回。否则,我想继续并使用包含数组索引的变量索引。查找数组中没有空值的索引
int index;
for (int i = 0; i < e.length; i++) {
if (e[i] != null) {
index = i;
break;
}
}
// if index did not get any value inside the for-loop, return
// And here I use the index that was found using the for-loop
我如何检查是否变量指数从for循环得到了一个新的指数?
谢谢!
添加一个布尔变量和设置在你休息之前它是真实的。 – nhahtdh 2013-04-24 15:04:40