Java Reference
In-Depth Information
«interface»
java.util.Collection<E>
«interface»
java.util.List < E >
+ add(index: int, element: Object): boolean
+ addAll(index: int, c: Collection<? extends E>)
: boolean
+ get(index: int): E
+ indexOf(element: Object): int
+ lastIndexOf(element: Object): int
+ listIterator(): ListIterator<E>
+ listIterator(startIndex: int): ListIterator<E>
+ remove(index: int): E
+ set(index: int, element: Object): Object
+ subList(fromIndex: int, toIndex: int): List<E>
Adds a new element at the specified index.
Adds all the elements in c to this list at the specified
index.
Returns the element in this list at the specified index.
Returns the index of the first matching element.
Returns the index of the last matching element.
Returns the list iterator for the elements in this list.
Returns the iterator for the elements from startIndex .
Removes the element at the specified index.
Sets the element at the specified index.
Returns a sublist from fromIndex to toIndex-1 .
F IGURE 20.3
The List interface stores elements in sequence and permits duplicates.
The listIterator() or listIterator(startIndex) method returns an instance of
ListIterator . The ListIterator interface extends the Iterator interface to add bidi-
rectional traversal of the list. The methods in ListIterator are listed in Figure 20.4.
«interface»
java.util.Iterator < E >
«interface»
java.util.ListIterator<E>
+ add(element: E): void
+ hasPrevious(): boolean
Adds the specified object to the list.
Returns true if this list iterator has more elements
when traversing backward.
Returns the index of the next element.
Returns the previous element in this list iterator.
Returns the index of the previous element.
Replaces the last element returned by the previous or
next method with the specified element.
+ nextIndex(): int
+ previous(): E
+ previousIndex(): int
+ set(element : E): void
F IGURE 20.4
ListIterator enables traversal of a list bidirectionally.
The add(element) method inserts the specified element into the list. The element is
inserted immediately before the next element that would be returned by the next() method
defined in the Iterator interface, if any, and after the element that would be returned by
the previous() method, if any. If the list doesn't contain any elements, the new element
becomes the sole element in the list. The set(element) method can be used to replace
the last element returned by the next method or the previous method with the specified
element.
The hasNext() method defined in the Iterator interface is used to check whether the
iterator has more elements when traversed in the forward direction, and the hasPrevious()
 
 
Search WWH ::




Custom Search