title: Java collect with lambda expression example
body: <p>I was trying to convert this </p>
  
  <pre><code> String r = "";
   for ( Persona p : list ) {
      r += p.lastName;
   }
  </code></pre>
  
  <p>To <code>stream().filter.collect()</code> form, but I want to know how to write the <code>collect</code> with <strong>a lambda expression</strong> (not method references). I couldn't find a good example.</p>
  
  <p>This is what I have</p>
  
  <pre><code>class B {
      public static void main( String ... args ) {
          List&lt;Person&gt; p = Arrays.asList(
                  new Person("John", "Wilson"),
                  new Person("Scott", "Anderson"),
                  new Person("Bruce", "Kent"));
  
          String r;
          String s = p.stream()
              .filter( p -&gt; p.lastName.equals("kent"))
              .collect((r, p) -&gt; r += p.lastName);/// ?????
      }
  }
  class Person {
      String name;
      String lastName;
      public Person( String name, String lastName ) {
          this.name = name;
          this.lastName = lastName;
      }
  }
  </code></pre>
  
  <p>All the examples I find are using method references whereas I <strong><em>think</em></strong> there should be an easy way to write a lambda expression instead.</p>