Java Reference
In-Depth Information
public abstract class AbstractCollection<AnyType>
implements Collection<AnyType>
{
public boolean removeAll ( Collection<? extends AnyType> c )
{
Iterator<AnyType> itr = this.iterator( );
boolean wasChanged = false;
while( itr.hasNext( ) )
{
if( c.contains( itr.next( ) ) )
{
itr.remove( );
wasChanged = true;
}
}
return wasChanged;
}
...
}
a.
Suppose
LinkedList
extends
AbtractCollection
and does not over-
ride
removeAll
. What is the running time of
removeAll
when
c
is a
List
?
b.
Suppose
LinkedList
extends
AbstractCollection
and does not over-
ride
removeAll
. What is the running time of
removeAll
when
c
is a
TreeSet
?
c.
Suppose
ArrayList
extends
AbstractCollection
and does not over-
ride
removeAll
. What is the running time of
removeAll
when
c
is a
List
?
d.
Suppose
ArrayList
extends
AbstractCollection
and does not over-
ride
removeAll
. What is the running time of
removeAll
when
c
is a
TreeSet
?
e.
What is the result of calling
c.removeAll(c)
using the implemen-
tation above?
f.
Explain how to add code so that a call such as
c.removeAll(c)
clears the collection.
Write a test program to see which of the following calls successfully
clears a java
LinkedList
.
c.removeAll( c );
c.removeAll( c.subList ( 0, c.size( ) );
6.19
Search WWH ::
Custom Search