本帖最后由 影子木木 于 2012-10-4 19:33 编辑
public static ArrayList getNewList(ArrayList list){
ArrayList newAl = new ArrayList();
for (Iterator iterator = list.iterator();iterator.hasNext();) {
Object object = iterator.next();
if (!newAl.contains(object))
newAl.add(object);
}
// for (int i = 0; i < list.size(); i++) {
// if (!newAl.contains(list.get(i))) {
// newAl.add(newAl.add(list.get(i)));
// }
// }
return newAl;
}
上面一个for是用Iterator做的, 怎么下面一个for循环达不到上面for循环的要求呢? |