【发布时间】:2011-06-08 19:17:45
【问题描述】:
到目前为止,我有以下代码:
/*
* This method adds only the items that don’t already exist in the
* ArrayCollection. If items were added return true, otherwise return false.
*/
public boolean addAll(Collection<? extends E> toBeAdded) {
// Create a flag to see if any items were added
boolean stuffAdded = false;
// Use a for-each loop to go through all of the items in toBeAdded
for (something : c) {
// If c is already in the ArrayCollection, continue
if (this.contains(c)) { continue; }
// If c isn’t already in the ArrayCollection, add it
this.add(c)
stuffAdded = true;
}
return stuffAdded;
}
}
我的问题是:我应该用什么替换某些东西(和 c)来完成这项工作?
【问题讨论】:
-
this.contains()?你的对象实现了 Collection 吗?
-
@Cosmin,可能是因为他在这里实现
addAll:-)