Chapter 13. Lists

Lists are probably the most widely used Java collections in practice. A list is a collection which—unlike a set—can contain duplicates, and which—unlike a queue—gives the user full visibility and control over the ordering of its elements. The corresponding Collections Framework interface is List<E>.

The List interface exposes methods for positional access, for searching for a given value, for generating views, and for creating ListIterators—a subtype of Iterator with additional features that take advantage of a List’s sequential nature. In addition, the methods inherited from SequencedCollection provide convenient shorter versions of common positional access calls. Finally, static factory methods are available to create unmodifiable Lists of different lengths.

Positional Access

These methods access elements based on their numerical position in the list.

void add(int index, E e) // adds element e at given index ...

Get Java Generics and Collections, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.