Java TOPIC 19 – JAVA COLLECTIONS I - LISTS LESSON NOTE 2 LIST We
will look at two implementations of the List interface. The classes we will look at are ArrayList and LinkedList. Both
provide the user with the same functionality because they are both Lists. ARRAYLIST &
LINKEDLIST METHODS Here
is a listing of the most useful methods for lists:
Of course,
using an IDE like Eclipse makes using a new Class so easy because you can see
all the method options that you have. IMPLEMENTATION
DIFFERENCES An ArrayList object provides all List functionality to the
data that is actually stored in an array.
It is very efficient at looking up the content of a specific
index. It is inefficient when adding
or removing elements because arrays are static sizes and resizing involves
copying all existing data over into a larger/smaller array. A LinkedList object provides all List functionality to the
data that is stored as a chain of individual nodes that reference the next
element in the chain. It is very
efficient as adding and removing elements (if used correctly). However, it is inefficient at looking up
specific elements located at a specific index. Note that we will take a closer look at LinkedLists later.
|
||
|