title: How to convert single element list to java 8 optional
body: <p>How to nicely convert list containing one or zero elements to Optional?</p>
  
  <p>The ugly code:</p>
  
  <pre><code>List&lt;Integer&gt; integers = new ArrayList&lt;&gt;();
  
  Optional&lt;Integer&gt; optional = integers.size() == 0 ?
          Optional.empty() :
          Optional.of(integers.get(0));
  </code></pre>