Skip to Content
Java in a Nutshell, 5th Edition
book

Java in a Nutshell, 5th Edition

by David Flanagan
March 2005
Intermediate to advanced
1254 pages
104h 21m
English
O'Reilly Media, Inc.
Content preview from Java in a Nutshell, 5th Edition

Name

List<E>

Synopsis

This interface represents an ordered collection of objects. In Java 5.0 List is a generic interface and the type variable E represents the type of the objects in the list. Each element in a List has an index, or position, in the list, and elements can be inserted, queried, and removed by index. The first element of a List has an index of 0. The last element in a list has index size( )-1.

In addition to the methods defined by the superinterface, Collection, List defines a number of methods for working with its indexed elements. get( ) and set( ) query and set the object at a particular index, respectively. Versions of add( ) and addAll( ) that take an index argument insert an object or Collection of objects at a specified index. The versions of add( ) and addAll( ) that do not take an index argument insert an object or collection of objects at the end of the list. List defines a version of remove( ) that removes the object at a specified index.

The iterator( ) method is just like the iterator( ) method of Collection, except that the Iterator it returns is guaranteed to enumerate the elements of the List in order. listIterator( ) returns a ListIterator object, which is more powerful than a regular Iterator and allows the list to be modified while iteration proceeds. listIterator( ) can take an index argument to specify where in the list iteration should begin.

indexOf( ) and lastIndexOf( ) perform linear searches from the beginning and end, respectively, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java in a Nutshell, 8th Edition

Java in a Nutshell, 8th Edition

Benjamin J. Evans, Jason Clark, David Flanagan
Java in a Nutshell, 7th Edition

Java in a Nutshell, 7th Edition

Benjamin J. Evans, David Flanagan
Learning Java, 5th Edition

Learning Java, 5th Edition

Marc Loy, Patrick Niemeyer, Daniel Leuck
Learning Java, 4th Edition

Learning Java, 4th Edition

Patrick Niemeyer, Daniel Leuck

Publisher Resources

ISBN: 0596007736Supplemental ContentErrata Page