【发布时间】:2016-10-13 03:59:17
【问题描述】:
如果工人的名字以removeWorker() 方法接受的分配字母开头,我有这种方法可以删除工人。有人可以解释第二个for 循环是如何工作的吗?
public void removeWorker(String s) {
if (index == 0) {
System.out.println("There is any worker in array!");
return;
}
for (int i = 0; i < index; i++) {
if (worker[i].getName().startsWith(s)) {
for (int j = i; j < index - 1; j++) {
worker[j] = worker[j + 1];
}
worker[--index] = null;
i--;
}
}
}
【问题讨论】:
-
索引变量代表什么,你初始化它了吗?
标签: java arrays for-loop void removeall