title: Create a Stream using Scanner
body: <p>This is usually how I accept an <code>Array</code> from a user. I ask for the size, then loop and populate the <code>Array</code>. </p>
  
  <pre><code>Scanner scan = new Scanner(System.in);
  int N = scan.nextInt();
  int[] numbers = new int[N];
  for (int n=0; n&lt;N; n++){
      numbers[n] = scan.nextInt();
  }
  </code></pre>
  
  <p>I have been trying to learn java 8 and I noticed that the <code>Random</code> class has a method now to create a stream. It is pretty easy now to declare a n-sized array with random numbers. </p>
  
  <pre><code>int[] randomNumbers = new Random().ints().limit(N).toArray();
  </code></pre>
  
  <p>What I have been trying to do is create an array doing something similar with either streams or lambda expressions but for user input. What I tried doing is creating an <code>IntStream</code>, map the values to <code>Scanner#nextInt</code>, then create an array. </p>
  
  <pre><code>int[] numbers = new IntStream().map(x -&gt; scan.nextInt()).limit(N).toArray();
  </code></pre>
  
  <p>What I <em>can</em> do is something like this:</p>
  
  <pre><code>int[] numbers = new int[N];
  Arrays.fill(numbers, 0);
  numbers = Arrays.stream(numbers).map(x -&gt; scan.nextInt()).toArray();
  System.out.println(Arrays.toString(numbers));
  </code></pre>
  
  <p>But that still feels a bit redundant. Filling the array with some arbitrary number only to replace it in the next line. </p>