title: How can I return a value while checking if a Java 8 Optional is present?
body: <p>How can I return a value but make sure checking .get() is valid?</p>
  
  <p>Assume <code>date</code> is an <code>Optional&lt;String&gt;</code>.</p>
  
  <pre><code>methodThatTakesStringParam(date.ifPresent(s-&gt;s.get().replace("-", ""))) );  
  </code></pre>
  
  <p>If I just use this and .get is performed it throws if its not present!</p>
  
  <pre><code>methodThatTakesStringParam( date.get().replace("-", "") );  
  </code></pre>
  
  <p>How do I handle this? All the examples I see are something like </p>
  
  <pre><code>date.ifPresent(System.out.println("showing that you can print to io is useless to me =)") 
  </code></pre>
  
  <p>but I want to return a string in this case -- the empty string if .ifPresent() is false.</p>