Lab 11, CSC 102, Spring 2012
In a test class, declare an array of strings, using the curly-brace syntax.
Use the Arrays.asList static method to transform it into a List<String>. Give this value the name listOfStrings.
Develop the static method hasAppleIter, that accepts an Iterable<String> and returns true when the specified sequence contains the string "apple". Compare the strings using the .equals method. Use the foreach loop, as in lecture on Monday. Test it by calling it on listOfStrings.
Implement an iterator for your existing StringList hierarchy. It should be called SLIterator, and it should act as an iterator for the list that it is initialized with. Keep in mind that an iterator must mutate itself, and not the list that it refers to.
In order to make the Java Person happy, you must have a bogus "Remove" method in your class. It should look like this:
public void remove(){
throw new UnsupportedOperationException();
}
Test your iterator by calling the next and hasNext methods.
Once your iterator is working, modify your StringList hierarchy so that it implements Iterable, and can create iterators on demand. The implementation of the iterator method is going to be a one-liner, as it was in lecture.
Test that the StringList is iterable by passing it to your hasAppleIter method.
}
]