List list=new ArrayList();
list.add(new ForTest("1"));
list.add(new ForTest("2"));
list.add(new ForTest("3"));
list.add(new ForTest("4"));
list.add(new ForTest("5"));
list.add(new ForTest("6"));
list.add(new ForTest("7"));
for (int i = 0; i < list.size(); i++) {
ForTest test=list.get(i);
if(test.getFlag().equals("3")){
list.remove(i);
}
//System.out.println("循環到:"+i+",list.get(i).getFlag()="+list.get(i).getFlag());
System.out.println("循環到:"+i+",flag="+test.getFlag());
}
}
這麼寫
for (int i = list.size()-1; i >=0; i--)