java问题,请大神指教?!
ExecutorServiceexecutor=Executors.newSingleThreadExecutor();List<String>list=newArray...
ExecutorService executor = Executors.newSingleThreadExecutor();
List<String> list = new ArrayList<String>();
list.add("111");
list.add("222");
list.add("333");
for(int i=0;i<list.size();i++){
int index=i;
executor.execute(new Runnable() {
@Override
public void run() {
try {
delete(list.get(index));
} catch (KMException e) {
e.printStackTrace();
}
}
});
}
遍历时为啥不能直接用 list.get(i) 索引,而要int index=i,list.get(index) 呢,求大神指教? 展开
List<String> list = new ArrayList<String>();
list.add("111");
list.add("222");
list.add("333");
for(int i=0;i<list.size();i++){
int index=i;
executor.execute(new Runnable() {
@Override
public void run() {
try {
delete(list.get(index));
} catch (KMException e) {
e.printStackTrace();
}
}
});
}
遍历时为啥不能直接用 list.get(i) 索引,而要int index=i,list.get(index) 呢,求大神指教? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询