import java.util.Iterator;
import java.util.ListIterator;
public class MainClass {
public static void main(String args[]) {
ArrayList
al.add("C");
al.add("A");
al.add("E");
al.add("B");
al.add("D");
al.add("F");
System.out.print("Original contents of al: ");
Iterator
while (itr.hasNext()) {
String element = itr.next();
System.out.print(element + " ");
}
System.out.println();
ListIterator
while (litr.hasNext()) {
String element = litr.next();
litr.set(element + "+");
}
// Now, display the list backwards.
System.out.print("Modified list backwards: ");
while (litr.hasPrevious()) {
String element = litr.previous();
System.out.print(element + " ");
}
}
/*things I've learned in this exercise:
Iterator takes the place of Enumeration in the Java collections framework.
- Iterators allow the user to remove elements from the underlying collection during the iteration.
- Method names have been improved in this Interface.
*/
No comments:
Post a Comment