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