title: Java 8 - Update two properties in same Stream code
body: <p>I'm wondering if there is a way I can update two times an object in a <code>Stream</code> lambda code, I need to update two properties of a class, I need to update the <code>value</code> and the <code>recordsCount</code> properties</p>
  <p>Object:</p>
  <pre><code>public class HistoricDataModelParsed {
  
  private Date   startDate;
  private Date   endDate;
  private Double value;
  private int    recordsCount;
  
  }
  </code></pre>
  <p>I tried doing something like this:</p>
  <pre><code>val existingRecord = response.stream()
       .filter(dateTime -&gt;fromDate.equals(dateTime.getStartDate()))
       .findAny()
       .orElse(null);
  
  
  response.stream()
       .filter(dateTime -&gt;fromDate.equals(dateTime.getStartDate()))
       .findAny()
       .orElse(existingRecord)
       .setValue(valueAdded)
       .setRecordsCount(amount);
  </code></pre>
  <p>But I got this error: <strong>&quot;Cannot invoke <code>setRecordsCount(int)</code> on the primitive type void&quot;</strong></p>
  <p>So I ended up doing the stream two times to update each of the two fields I needed</p>
  <pre><code>response.stream()
       .filter(dateTime -&gt;fromDate.equals(dateTime.getStartDate()))
       .findAny()
       .orElse(existingRecord)
       .setValue(valueAdded);
                  
   response.stream()
       .filter(dateTime -&gt;fromDate.equals(dateTime.getStartDate()))
       .findAny()
       .orElse(existingRecord)
       .setRecordsCount(amount);      
  </code></pre>
  <p>Is there a way I can achieve what I need without the need to stream two times the list?</p>