Java 8 streams "ifPresent"
<p>I am trying to learn about streams and encountered a problem:
I want to get the minimal value of a list and assign it to an int variable.
For that I did the following:</p>

<pre><code>List&lt;Integer&gt; list = new ArrayList&lt;&gt;();
    list.add(1);
    list.add(2);
    list.add(3);
    int smallest = list.stream().min(Integer::compareTo).get();
    System.out.println(smallest);
</code></pre>

<p>This works well and i get <code>1</code> as a result.
The issue is that the IDE gives the warning that <code>Optional.get</code> is called before checking for <code>.isPresent</code>.
To fix that i used the slightly different <code>ifPresent</code> method and tried the following:</p>

<pre><code>int smallest = list.stream().min(Integer::compareTo).ifPresent(integer -&gt; integer);
</code></pre>

<p>Unfortunately this doesn't work since I get the warning: <code>Bad return type in Lambda, Integer cannot be converted to void.</code>
My question finally is: How can I assign the min value to the <code>int smallest</code> variable WITH checking ifPresent?</p>