Java Collection (set)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.