title: Java 8 Collectors.toMap SortedMap
body: <p>I'm using Java 8 lambdas and want to use <code>Collectors</code> <code>toMap</code> to return a <code>SortedMap</code>. The best I can come up with is to call the following <code>Collectors</code> <code>toMap</code> method with a dummy <code>mergeFunction</code> and <code>mapSupplier</code> equal to <code>TreeMap::new</code>.</p>
  
  <pre><code>public static &lt;T, K, U, M extends Map&lt;K, U&gt;&gt;
          Collector&lt;T, ?, M&gt; toMap(Function&lt;? super T, ? extends K&gt; keyMapper,
                  Function&lt;? super T, ? extends U&gt; valueMapper,
                  BinaryOperator&lt;U&gt; mergeFunction,
                  Supplier&lt;M&gt; mapSupplier) {
      BiConsumer&lt;M, T&gt; accumulator = (map, element) -&gt; map.merge(keyMapper.apply(element),
              valueMapper.apply(element), mergeFunction);
      return new CollectorImpl&lt;&gt;(mapSupplier, accumulator, mapMerger(mergeFunction), CH_ID);
  }
  </code></pre>
  
  <p>I don't want to pass in a merge function though, as I just want <code>throwingMerger()</code>, in the same way as the basic <code>toMap</code>implementation as follows:</p>
  
  <pre><code>public static &lt;T, K, U&gt;
          Collector&lt;T, ?, Map&lt;K, U&gt;&gt; toMap(Function&lt;? super T, ? extends K&gt; keyMapper,
                  Function&lt;? super T, ? extends U&gt; valueMapper) {
      return toMap(keyMapper, valueMapper, throwingMerger(), HashMap::new);
  }
  </code></pre>
  
  <p>What would be the best practise method of using <code>Collectors</code> to return a <code>SortedMap</code>?</p>