Extracting numbers from file using stream and lambda expressions
<p>I'm trying to extract only numbers from my <code>List&lt;String&gt; list</code> using Java 8 stream and lambda expression. First what I had to do was to load Strings from file to list. After that I filtered stream to get Strings which contain "PL".</p>

<p>My file:</p>

<pre><code>Jan Kowalski PL 35000
Jiri Prohazka CZ 28000
Anna Malinowska PL 52000
Jozef Bak PL 49999
Helmut Schnittke DE 45000
Kleofas Oginski PL 45000
John Bull US 74000
Lukasz Zolw PL 9400
Franz Beckenbauer DE 83000
Frantisek Kupka CZ 32000
</code></pre>

<p>Code:</p>

<pre><code>List&lt;String&gt; list = new ArrayList&lt;&gt;();
try (Stream&lt;String&gt; stream = Files.lines(Paths.get("file"),Charset.defaultCharset())) {
    list = stream
        .filter(line -&gt; line.contains("PL"))
        .peek(System.out::println)
        .collect(Collectors.toList());
}
</code></pre>

<p>I think the best way right now is to remove all letters from Strings and leave only decimals, but I have problem how should I do it.
The final result should let me parse elements of list to integer, sort them, and get the sum of the first three elements.
I already have done it, but I'm sure there's better way to do it (e.g. using only one list)</p>

<pre><code>List&lt;Integer&gt; iList = new ArrayList&lt;Integer&gt;();
        list.forEach(s-&gt;
        {
            s = s.replaceAll("\\D+","");
            iList.add(Integer.parseInt(s));
        });
        Collections.sort(iList);
        Collections.reverse(iList); 
        int sum = 0;
        for(int i=0;i&lt;3;i++){
            sum=sum+iList.get(i); 
        }
</code></pre>

<p>Any ideas how to do it without using any additional list?</p>