title: Input a dynamic array in java
body: <p>I am trying to input a dynamic array, the size is unknown at any point with input like this(Example)</p>
  
  <p>1 5 1 4 3 2 </p>
  
  <p>but cannot figure out how. I have a code that works partially but still need a perfect solution.  </p>
  
  <p>My Code:</p>
  
  <pre><code>Scanner sc = new Scanner(System.in);
  int T;
  T = sc.nextInt();
  for(int i=0; i&lt;T;i++){
  List&lt;Integer&gt; a = new ArrayList&lt;Integer&gt;();;
  int n=0;
  String temp;
  do{
       temp = sc.next();
       a.add(Integer.parseInt(temp));
       n++;
  }while(sc.hasNextInt());
  myfxn(a);
  }
  </code></pre>
  
  <p>this code waits until a non-numeric value is entered then it proceeds, I thought it would take Enter as that but it didn't. So I need to execute my code in a way that they take the whole array until an Enter is fired or line ends.</p>