title: How to map and collect primitive return type using Java 8 Stream
body: <p>I am new in Java 8 streams and I am wondering if there is way to perform <code>forEach/map</code> call on method returning a <code>byte</code> and accepting an <code>int</code> as parameter.</p>
  
  <p>Example:</p>
  
  <pre><code>public class Test {
     private byte[] byteArray; // example of byte array
  
     public byte getByte(int index) {
        return this.byteArray[index];
     }
  
     public byte[] getBytes(int... indexes) {
        return Stream.of(indexes)
               .map(this::getByte) // should return byte
               .collect(byte[]::new); // should return byte[]
     }
  }
  </code></pre>
  
  <p>As you may guess, the <code>getBytes</code> method not working. <code>"int[] cannot be converted to int"</code>Probably somewhere is missing foreach, but personally cant figure it out.</p>
  
  <p>However, this is working, old-fashioned approach which I would like to rewrite as Stream.</p>
  
  <pre><code>byte[] byteArray = new byte[indexes.length];
  for ( int i = 0; i &lt; byteArray.length; i++ ) {
     byteArray[i] = this.getByte( indexes[i] );
  }
  return byteArray;
  </code></pre>