Java Reference
In-Depth Information
Figure 10
A Concrete View of an Array List
Figure 11
An Abstract View of an Array List
683
684
An array list allows random access to all elements. You specify an integer index, and
you can get or set the corresponding element.
public class ArrayList
{
public Object get(int index) { . . . }
public void set(int index, Object element) { . .
. }
. . .
}
With a linked list, on the other hand, element access is a bit more complex. A linked
list allows sequential access. You need to ask the linked list for an iterator. Using that
iterator, you can easily traverse the list elements one at a time. But if you want to go
to a particular element, say the 100th one, you first have to skip all elements before it.
public class LinkedList
{
public ListIterator listIterator() { . . . }
Search WWH ::




Custom Search