List Implementations That Use Arrays
List Implementations That Use Arrays
3
An Analogy
5
Adding a Student
7
AList add() Methods
First add method adds a new item at the
end of the list
• Assign new value at end
• Increment length of list
8
Adding Items in Mid-list
10
Removing a List Entry
12
Dynamic Array Expansion
13
Dynamic Array Expansion
Vector
• Found in package java.util
• Has methods for manipulating entries
• Enables implementing the ADT List
16
Using a Vector
18
Using a Vector
The add() methods
• The first uses the addElement method from
the Vector class
• The other uses the insertElementAt
method
The remove() method
• Uses the removeElementAt method
19
Pros and Cons of Array Use for the ADT List
20
Java Class Library
Has a class similar to class AList defined
in this chapter
• Class ArrayList
• Uses dynamic array expansion
Interface Serializable
• Represent an object as a sequence of bytes to
be written to a file
• Add the words implements Serializable
to class definition
public class AList implements ListInterface, Serializable
{ ... 21