Question
3) An Iterator (that is an object that has the methods in the Iterator interface) allows access to each data element in a collection. How
3) An Iterator (that is an object that has the methods in the Iterator interface) allows access to each data element in a collection. How is that different from simply concatenating the values of the fields of all the data elements into a long string using the toString( ) method for a collection such as an OrderedList or UnorderedList? public class ArrayIterator
pubic boolean hasNext( ) { //this method is supposed to return true if there are any data items //in the array that have not yet been accessed. You are to write the //one line of code to do this } public void remove( ) throws UnsupportedOperationExeption { //Because we are never going to use this method we will //simply create and throw and exception whenever this //method is called. This is not a Java built-in Exception class, //it is one the authors of the textbook created. throw new UnsupportedOperationException(The remove operation for this iterator is not + supported); } }//end of ArrayIterator class definition 6) Now write the class definition for the NothingLeftToIteratorOver exception used above.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started