Iterator iterative examples

Source: Internet
Author: User

1  PackageJihe;2 3 ImportJava.util.*;4 5  Public classIteratordemo {6     /*Create a new Iteratordemo class in your project, creating a ArrayList collection in your class that specifies the generic type as an integer.7 * and add 10 elements to it, iterating through the ArrayList collection, with the loop condition that if there are still elements in the iterator that can iterate,8 * Continue the loop and if not, jump out of the loop. 9      **/Ten  One      Public Static voidMain (string[] args) { A         //TODO Auto-generated method stubs -         //To create a collection test class -List<integer> list=NewArraylist<integer>(); the         //to add a range of elements -          for(inti=0;i<10;i++) -         { -List.add (i);//Add 10 elements +         } -         //enter 10 elements into the collection +System.out.println ("All elements in the output list"); A         //iterator Iteration atIterator<integer> it=list.iterator (); -         //if the next right element in the iterator continues to loop -          while(It.hasnext ()) -         { -             //enter the next element into the collection and continue the loop -System.out.print ("\ T" +It.next ()); in         } -  to     } +  -}

Iterator iterative examples

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.