Lambda Java 8 - How to convert while streaming a String List to a Date List
<p>Is there a way to also convert (while streaming and collecting) a List of Strings to a new List of Dates?</p>

<p><strong>My attempt:</strong></p>

<p>I defined a SimpleDateFormat and tried to use that in the follwing code, but I can't get it working all together.</p>

<pre><code>SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd.mm.yyyy");

ArrayList&lt;Date&gt; dateList = stringList.stream()
              .filter(s -&gt; s.startsWith("&lt;"))
              .collect(Collectors.toList());
</code></pre>

<p><strong>Solution</strong></p>

<p>Based on the hints to use map, I got a working solution for now that looks like this. Of course any optimization on this is welcomed!</p>

<pre><code>int year = 2016;
int month = 2;
int day = 15;


final List&lt;LocalDate&gt; dateListEarlier = dateList.stream()
        .filter(s -&gt; s.startsWith("&lt;"))
        .map(s -&gt; s.substring(1).trim())
        .map(s -&gt; LocalDate.parse(s, formatter))
        .sorted()
        .filter(d -&gt; d.isAfter(LocalDate.of(year, month, day)))
        .collect(Collectors.toList());
</code></pre>