title: Java8 : stream findFirst result
body: <p>I want to know if there is a way to get rid of the warning at <code>findFirst().get()</code> without using <code>.orElse()</code> when I know 100% that every time there is a result, so I never get a <code>NoSuchElementException</code>. </p>
  
  <p>For example let's see the following code:</p>
  
  <pre><code>    List&lt;String&gt; myList = new ArrayList&lt;&gt;();
      myList.add("Test");
      myList.add("Example");
      myList.add("Sth");
  
      String fisrstString = myList.stream().findFirst().get(); // here I surely get "Test" 
  </code></pre>
  
  <p>I don't know how other IDEs treat this, but IntelliJ treats that as a warning</p>
  
  <blockquote>
    <p>'Optional.get()' without 'isPresent()'</p>
  </blockquote>
  
  <p>I think probably it doesn't know when can you get <code>NoSuchElementException</code> there and when not, or I have no idea why. I know there are ways to solve this warning(<code>isPresent()</code> check, <code>.orElse(something)</code>) but with useless code, so simply I don't want to use those solutions because they are so unnecessary.</p>
  
  <p>Do you have any idea what can I do, or explain how is that treated by the IDE?</p>