Java Reference
In-Depth Information
Normal View of the Set: [1, 2, 3, 4, 5]
Reverse view of the set: [5, 4, 3, 2, 1]
Getting subset of the set
3 or more: [3, 4, 5]
Searching through the set
lower(3): 2
floor(3): 3
higher(3): 4
ceiling(3): 3
Polling elements from the set
pollFirst(): 1
Navigable Set: [2, 3, 4, 5]
pollLast(): 5
Navigable Set: [2, 3, 4]
pollFirst(): 2
Navigable Set: [3, 4]
pollFirst(): 3
Navigable Set: [4]
pollFirst(): 4
Navigable Set: []
pollFirst(): null
pollLast(): null
Working with Lists
A
list
is an ordered collection of objects. Sometimes a list is also known as a
sequence
. An instance of the
List
interface
represents a list in the Collections Framework. A list can have duplicate elements. You can also store multiple
null
values in a list.
The
List
interface inherits the
Collection
interface. It adds methods to support access to elements of the
List
using indexes. It also allows you to add an element to the end of the
List
or at any position identified by an integer
called the
index
. The index of an element in a
List
is zero-based. That is, the first element of the
List
has an index of
0, the second element has an index of 1, and so on. Figure
12-3
shows a
List
with four elements and their indexes.
Index >>
0
1
2
3
Element >>
John
Richard
Donna
Ken
Figure 12-3.
A pictorial view of a List with four elements