1 *java.util.ListIterator* *ListIterator* An iterator for lists that allows the pr
3 public interface interface ListIterator<E>
5 implements |java.util.Iterator|
7 |java.util.ListIterator_Description|
8 |java.util.ListIterator_Fields|
9 |java.util.ListIterator_Constructors|
10 |java.util.ListIterator_Methods|
12 ================================================================================
14 *java.util.ListIterator_Methods*
15 |java.util.ListIterator.add(E)|Inserts the specified element into the list (opt
16 |java.util.ListIterator.hasNext()|Returns true if this list iterator has more e
17 |java.util.ListIterator.hasPrevious()|Returns true if this list iterator has mo
18 |java.util.ListIterator.next()|Returns the next element in the list.
19 |java.util.ListIterator.nextIndex()|Returns the index of the element that would
20 |java.util.ListIterator.previous()|Returns the previous element in the list.
21 |java.util.ListIterator.previousIndex()|Returns the index of the element that w
22 |java.util.ListIterator.remove()|Removes from the list the last element that wa
23 |java.util.ListIterator.set(E)|Replaces the last element returned by next or p
25 *java.util.ListIterator_Description*
27 An iterator for lists that allows the programmer to traverse the list in either
28 direction, modify the list during iteration, and obtain the iterator's current
29 position in the list. A ListIterator has no current element; its cursor
30 position always lies between the element that would be returned by a call to
31 previous() and the element that would be returned by a call to next(). An
32 iterator for a list of length n has n+1 possible cursor positions, as
33 illustrated by the carets (^) below:
35 Element(0) Element(1) Element(2) ... Element(n-1) cursor positions: ^ ^ ^ ^ ^
37 Note that the (|java.util.ListIterator|) and (|java.util.ListIterator|) methods
38 are not defined in terms of the cursor position; they are defined to operate on
39 the last element returned by a call to (|java.util.ListIterator|) or
40 (|java.util.ListIterator|) .
42 This interface is a member of the <a
43 href="/../technotes/guides/collections/index.html"> Java Collections Framework.
47 *java.util.ListIterator.add(E)*
51 Inserts the specified element into the list (optional operation). The element
52 is inserted immediately before the next element that would be returned by next,
53 if any, and after the next element that would be returned by previous, if any.
54 (If the list contains no elements, the new element becomes the sole element on
55 the list.) The new element is inserted before the implicit cursor: a subsequent
56 call to next would be unaffected, and a subsequent call to previous would
57 return the new element. (This call increases by one the value that would be
58 returned by a call to nextIndex or previousIndex.)
61 e - the element to insert.
63 *java.util.ListIterator.hasNext()*
65 public boolean hasNext()
67 Returns true if this list iterator has more elements when traversing the list
68 in the forward direction. (In other words, returns true if next would return an
69 element rather than throwing an exception.)
73 Returns: true if the list iterator has more elements when traversing the list in the
76 *java.util.ListIterator.hasPrevious()*
78 public boolean hasPrevious()
80 Returns true if this list iterator has more elements when traversing the list
81 in the reverse direction. (In other words, returns true if previous would
82 return an element rather than throwing an exception.)
86 Returns: true if the list iterator has more elements when traversing the list in the
89 *java.util.ListIterator.next()*
93 Returns the next element in the list. This method may be called repeatedly to
94 iterate through the list, or intermixed with calls to previous to go back and
95 forth. (Note that alternating calls to next and previous will return the same
100 Returns: the next element in the list.
102 *java.util.ListIterator.nextIndex()*
104 public int nextIndex()
106 Returns the index of the element that would be returned by a subsequent call to
107 next. (Returns list size if the list iterator is at the end of the list.)
111 Returns: the index of the element that would be returned by a subsequent call to next,
112 or list size if list iterator is at end of list.
114 *java.util.ListIterator.previous()*
116 public |E| previous()
118 Returns the previous element in the list. This method may be called repeatedly
119 to iterate through the list backwards, or intermixed with calls to next to go
120 back and forth. (Note that alternating calls to next and previous will return
121 the same element repeatedly.)
125 Returns: the previous element in the list.
127 *java.util.ListIterator.previousIndex()*
129 public int previousIndex()
131 Returns the index of the element that would be returned by a subsequent call to
132 previous. (Returns -1 if the list iterator is at the beginning of the list.)
136 Returns: the index of the element that would be returned by a subsequent call to
137 previous, or -1 if list iterator is at beginning of list.
139 *java.util.ListIterator.remove()*
143 Removes from the list the last element that was returned by next or previous
144 (optional operation). This call can only be made once per call to next or
145 previous. It can be made only if ListIterator.add has not been called after the
146 last call to next or previous.
150 *java.util.ListIterator.set(E)*
154 Replaces the last element returned by next or previous with the specified
155 element (optional operation). This call can be made only if neither
156 ListIterator.remove nor ListIterator.add have been called after the last call
160 e - the element with which to replace the last element returned by next or