through collection of elements one element at time an iterator consists of sequence sa current element in sand way of stepping to the next element in and making it the current element thusan iterator extends the concept of the position adt we introduced in section in facta position can be thought of as an iterator that doesn' go anywhere an iterator encapsulates the concepts of "placeand "nextin collection of objects we define the iterator adt as supporting the following two methodshasnext()test whether there are elements left in the iterator next()return the next element in the iterator note that the iterator adt has the notion of the "currentelement in traversal of sequence the first element in an iterator is returned by the first call to the method nextassuming of course that the iterator contains at least one element an iterator provides unified scheme to access all the elements of collection of objects in way that is independent from the specific organization of the collection an iterator for an array listlistor sequence should return the elements according to their linear ordering simple iterators in java java provides an iterator through its java util iterator interface we note that the java util scanner class (section implements this interface this interface supports an additional (optionalmethod to remove the previously returned element from the collection this functionality (removing elements through an iteratoris somewhat controversial from an object-oriented viewpointhoweverand it is not surprising that its implementation by classes is optional incidentallyjava also provides the java util enumeration interfacewhich is historically older than the iterator interface and uses names hasmoreelements(and nextelement(the iterable abstract data type in order to provide unified generic mechanism for scanning through data structureadts storing collections of objects should support the following methoditerator()return an iterator of the elements in the collection this method is supported by the java util arraylist class in factthis method is so importantthat there is whole interface