0

How can I implement a collection using a linked list by extending the Abstract collection? I'd have to use the void remove method if Iterator, and implement this and the add and size methods.

asked Apr 21, 2011 at 0:26

1 Answer 1

1

See the Java doc for AbstractCollection for more details:

To implement an unmodifiable collection, the programmer needs only to extend this class and provide implementations for the iterator and size methods. (The iterator returned by the iterator method must implement hasNext and next.)

To implement a modifiable collection, the programmer must additionally override this class's add method (which otherwise throws an UnsupportedOperationException), and the iterator returned by the iterator method must additionally implement its remove method.

public abstract int size()
public abstract Iterator<E> iterator()

Iterator defines this methods:

boolean hasNext()
E next()
void remove()
answered Apr 21, 2011 at 0:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.