java
.util
.List
is a child interface of Collection
.
It is an ordered collection of objects.
Since List
preserves the insertion order, it allows positional access and insertion of elements.
List interface is implemented by ArrayList , LinkedList , Vector , and Stack classes.
|
List is an interface, and the instances of List can be created in the following ways:
|
|
List
.
The type-safe List can be defined in the following way:
|
|
List
interface extends Collection
, hence it supports all the operations of Collection
interface, along with the additional operations: add
, remove
, get
, and set
operations such as
void add(int index, Object O)
:
This method adds given element at specified index.
for
loop is used to traverse unconditionally to all of the list items.
Other methods to iterate a list include (i) the classic array index loop such as for (int i = 0; i < collection.length; i++)
Iterator
hasNext()
/ next()
“You do not write your life with words... You write it with actions. What you think is not important. It is only important what you do.” ― Patrick Ness, A Monster Calls |