title: How to reference the result of reduce() operation in Java 8?
body: <p>I was trying to write a <code>mkString</code> function in Java8, a la Scala's useful <code>mkString</code> and ran into 2 issues that I could use some help on:</p>
  
  <ol>
  <li><p>I am unable to make the first argument of <code>mkString</code> a generic Collection reference like <code>Collection&lt;Object&gt; c</code> and have invokers call with ANY type of collection.</p></li>
  <li><p>Unable to reference the returned result of <code>reduce()</code> in-line to access the result's length to remove the extra leading separator.</p></li>
  </ol>
  
  <p>Here's the code : </p>
  
  <pre><code>public static void main(String[] args) {
      List&lt;Integer&gt; numbers = Arrays.asList(1, 2, 3, 4, 5);
      System.out.println(mkString(numbers, ","));
  
  }
  
  public static String mkString(Collection&lt;Integer&gt; c, String sep) {
      return c.stream()
              .map(e -&gt; String.valueOf(e))
              .reduce("", (a, b) -&gt; a + sep + b)
              .substring(1, &lt;&lt;&gt;&gt;.length);
  }
  </code></pre>