Interface listiterator<e>
Unique method:
Hasprevious () Determines whether the previous element exists.
Previous () The current pointer moves up one unit and then the element that the current pointer points to .
Next (); Remove the element that the current pointer points to, and then move the pointer down one unit.
Add (e) inserts the current element into the position pointed to by the current pointer.
Set (e) replaces the last element returned by the iterator.
Public Static voidMain (string[] args) {List List=NewArrayList (); List.add ("Iron Egg"); List.add ("Three fats."); List.add ("The dog's left."); List.add ("Tom"); SYSTEM.OUT.PRINTLN (list); Listiterator it= List.listiterator ();//returns an iterator specific to the list interfaceSystem.out.println ("There is a previous element:" + it.hasprevious ());//F//System.out.println ("Get previous element:" + it.previous ());//An exception occurredIt.next (); System.out.println ("Get previous element:" + it.previous ());//at the beginning is the point, the first element in the collection, after next, the pointer points to the second element in the collection and then takes out /*while (It.hasnext ()) {it.next (); It.previous (); }//It's a dead loop, and it's going back and forth.*//*only in that one place*/System.out.println (); while(It.hasnext ()) {System.out.println (It.next ()); } System.out.println (); while(It.hasprevious ()) {System.out.println ("Element is:" +it.previous ()); } System.out.println (); SYSTEM.OUT.PRINTLN (list); It.next (); It.next ();//The pointer moves two times.It.add ("Jack"); SYSTEM.OUT.PRINTLN (list);//is list, not output itSystem.out.println (); It.next (); It.next (); It.set ("Mmmmmmmmm");//replaces the last element returned by the iterator. So the last return without iterators is not possible (the It.next () here is the last return)SYSTEM.OUT.PRINTLN (list);//then throw java.lang.IllegalStateException }}
False0
Java Collection (set)