Iterator and ListIterator in Java
Iterator and ListIterator in Java
Iterator it = list.iterator();
while (it.hasNext())
System.out.println(it.next());
Iterator
ListIterator
+add(o: Obj ect) : void Adds the s pecifi ed object to the list
+hasPrevious() : boolean Return s tru e if this list iterator has more elements
when traversing backward.
+next Index() : int Return s the i ndex of the next element
+previousIndex() : i nt Return s the i ndex of the previosu element
+previous() : Ob ject Return s the p revious el ement i n this list iterator
+set(o: Object ) : void Replaces the l ast elemen t returned b y the previ ous
or next method with t he specified elem ent
Output:
green
yellow
red
red
yellow
green