title: How can a user input an array of any length in java?
body: <p>I'm writing a program in java that requires the user to input a series of numbers, for example <code>1 2 3 4 ..</code> until the user decides to stop and press enter. Normally what I would do is something like this </p>
  
  <pre><code>Scanner scan = new Scanner (System.in);    
  int[] array = new int[i];    
  for (int x = 0; x &lt; i; ++x)    
  {    
      array[i] = scan.nextInt();      
  }    
  </code></pre>
  
  <p>The problem is, in most cases i would have a set value. For example, I would ask how many numbers are going to be entered or something like that and that would be stored into i. In this case, i doesn't have a set value to begin with. The user should have the ability to enter as many numbers as he/she wants. Any suggestions?</p>
  
  <p>I tried this and I know the problem with it is that it will never exit the loop but maybe I'm on the right track or something so I'll post it here anyway.    </p>
  
  <pre><code>for (int i = 0; i &lt; x; i++, x++)    
  {    
      numbers[i] = scan.nextInt();    
      numbers = new double[x];                    
  }
  </code></pre>