I am learning stacks and find them pretty amusing, however, my iteration through my user-defined stack is ouputting the following:
Also, the goal of the program is to have user enter the data until "end" is entered and then print the stack from top to bottom.
Error
insertionException in thread "main" java.util.ConcurrentModificationException
at java.util.Vector$Itr.checkForComodification(Vector.java:1156)
at java.util.Vector$Itr.next(Vector.java:1133)
at Stacker.main(Stacker.java:29)
Program
import java.util.*;
public class Stacker {
public static void main(String[]args)
{
Scanner input = new Scanner(System.in);
Stack<String> stackInformation = new Stack<String>();
Iterator<String> iter = stackInformation.iterator();
String stackAdd = input.nextLine();
while (!stackAdd.equalsIgnoreCase("end"))
{
stackInformation.push(stackAdd);
stackAdd = input.nextLine();
}
System.out.println("Exited stack insertion");
while(iter.hasNext() && iter.next()!=null)
{
System.out.println(iter.next());
}
}
}