title: Using a Collector on a primitive stream
body: <p>Is there in Java 8 any way to use <a href="http://download.java.net/jdk8/docs/api/java/util/stream/Stream.html#collect-java.util.stream.Collector-" rel="nofollow">Stream::collect(Collector)</a> on primitive streams?</p>
  
  <p>Normally a <code>Stream&lt;Integer&gt;</code> as example has two methods for collecting:</p>
  
  <ul>
  <li><a href="http://download.java.net/jdk8/docs/api/java/util/stream/Stream.html#collect-java.util.stream.Collector-" rel="nofollow"><code>&lt;R,A&gt; R collect(Collector&lt;? super T,A,R&gt; collector)</code></a></li>
  <li><a href="http://download.java.net/jdk8/docs/api/java/util/stream/Stream.html#collect-java.util.function.Supplier-java.util.function.BiConsumer-java.util.function.BiConsumer-" rel="nofollow"><code>&lt;R&gt; R collect(Supplier&lt;R&gt; supplier,
            BiConsumer&lt;R,? super T&gt; accumulator,
            BiConsumer&lt;R,R&gt; combiner)</code></a></li>
  </ul>
  
  <p>However <code>IntStream</code> only has one method for collecting:</p>
  
  <ul>
  <li><a href="http://download.java.net/jdk8/docs/api/java/util/stream/IntStream.html#collect-java.util.function.Supplier-java.util.function.ObjIntConsumer-java.util.function.BiConsumer-" rel="nofollow"><code>&lt;R&gt; R collect(Supplier&lt;R&gt; supplier,
            ObjIntConsumer&lt;R&gt; accumulator,
            BiConsumer&lt;R,R&gt; combiner)</code></a></li>
  </ul>
  
  <p>Now as example code I have the following:</p>
  
  <pre><code>@Override
  public void run() {
      result = LongStream.range(1, maximum).boxed()
              .collect(Collectors.toMap(i -&gt; i, i -&gt; (int)Iterators.longStream(new CollatzGenerator(i)).count()))
              .entrySet().stream()
              .max(Comparator.comparingLong(Map.Entry::getValue))
              .get().getKey();
  }
  </code></pre>
  
  <p>As you can see I first box the primitives in order to be able to use a <code>Collectors.</code> method.</p>
  
  <p>Is there any way I can use primitives and still have the same code with <code>Collectors.toMap</code>
  ?</p>