Re: Collection Issue
adrian.bartholomew@gmail.com wrote:
[...]
public void removeAll(List<T> l, List<T> c) {
Iterator<T> e = l.iterator();
while (e.hasNext()) {
if (contains(l, e.next())) {//when it reaches the element,
it throws a null exception
e.remove(); // even though it DOES contain
it.
}
}
}
[...]
public boolean contains(List<T> c, T l) {
for (T e: c) {
if (e == l) return true;
}
return false;
}
What do you mean by "when it reaches the element?" What is
"the" element you're referring to? Unless I've missed something,
- The loop examines every element of List `l' in turn.
- It tests whether each element of `l' is contained in `l',
which seems like nothing more than a slow way to write `true'.
- Having determined that an element found in `l' is in fact
contained in `l', it then removes the element via the Iterator.
- When the loop finishes, `l' should be empty.
- The List `c' plays no role, and I don't see why it's there at
all.
Are you sure this is your actual code?
--
Eric.Sosman@sun.com