title: ConcurrentModificationException when printing the contents of a vector
body: <p>Ok so I'm wanting to write a program which allows the user to enter an infinite amount of numbers and then they would be printed in the same order again. </p>
  
  <p>I am getting this error:</p>
  
  <pre><code>Exception in thread "main" java.util.ConcurrentModificationException
      at java.util.Vector$Itr.checkForComodification(Unknown Source)
      at java.util.Vector$Itr.next(Unknown Source)
      at myPackage.Main.main(Main.java:41)
  </code></pre>
  
  <p>The 41st line is this line "System.out.println(itr.next());" one</p>
  
  <p>Here is my code:</p>
  
  <pre><code>package myPackage;
  
  import java.util.Scanner;
  import java.util.Vector;
  import java.lang.Integer;
  import java.util.Iterator;
  
  public class Main {
  
  private static Scanner user_input;
  
  public static void main(String[] args) {
  
      int first = 42;
      int second = 84;
  
      user_input = new Scanner(System.in);
  
      Vector&lt;Integer&gt; v = new Vector&lt;Integer&gt;();
  
      Iterator&lt;Integer&gt; itr = v.iterator();
  
      System.out.println("Please enter the numbers you wish to store temporarily before printing. When finished, enter either 42 or 84");
  
      int userInt = user_input.nextInt();
  
      while(user_input.equals(first) == false &amp;&amp; user_input.equals(second) == false){
  
          userInt = user_input.nextInt();
          if(userInt == 42 || userInt == 84){
              break;
          }
          else{
            v.add(userInt);
          }
      }
  
          System.out.println("Iterating through Vector elements...");
  
          while(itr.hasNext()){
               System.out.println(itr.next());
          }
  
      System.out.println("The program has terminated");
  }
  }
  </code></pre>
  
  <p>Did I mess up on the Iterator? Thanks in advance!</p>