TopRecursive Linked ListAbstractList class

AbstractList class

What operations can be implemented in AbstractList class to be shared?

For example:

    public E getFirst() \{
        return get(0);
    \}

However, there is no method get(int n) in the abstract class. There are two things going on here. First AbstractList implements interface List, which promises that there is such a get method. Normally this would force AbstractList to implement it. However, we can omit the implementations of required methods if we declare the class to be abstract.

When a class is declared to be abstract, we may not call its constructor, even if one is defined. Instead, the class may only be used to inherit from (even its constructor). We'll see in the code below how that works with the get(int n) method.

See details in AbstractList and AbstractCollection classes.

Linked Lists with Nodes

Linked list is composed of series of nodes, each of which has a reference to the next.

Must provide SinglyLinkedListElement class representing the nodes, and then construct LinkedList class using those nodes. Notice that SinglyLinkedListElement is a recursive structure as it contains an element also of type SinglyLinkedListElement. Unlike previous examples, we do not bother to introduce an interface and base and recursive classes. We do this to better match traditional approaches to linked lists, though we could have taken an approach more similar to those we saw earlier in the text.

See LinkedList example.


TopRecursive Linked ListAbstractList class