title: Conditional extract of value from Java Optional
body: <p>I am trying to find the most concise (and meaningful) way of using Java <code>Optional</code>, to read the first value off a <code>Optional&lt;String&gt;</code> and return the String if exists, or return "NOT_FOUND". Here is the code I am working with:</p>
  
  <pre><code>public static String getValue(Optional&lt;String&gt; input) {
      return input.ifPresent(val -&gt; val.get()).orElse("NOT_FOUND")
  }
  </code></pre>
  
  <p>The methods of Optional apparently have very specific purposes but the API has left me confused.</p>
  
  <p><strong>Update (4/13/2018):</strong>
  The code in my question is incorrect, because if I regarded <code>val</code> as the value inside the Optional, then <code>val.get()</code> does not make any sense. Thanks for pointing that out, @rgettman.</p>
  
  <p>Also, I added another part to my question in the accepted answer's comments, i.e. I needed a way to manipulate the String value, if present, before returning. The <code>orElse("NOT_FOUND")</code> is still applicable, if the Optional does not contain a value. So what is an acceptable use of the <code>Optional</code> API to achieve the following?</p>
  
  <pre><code>public static String getValue(Optional&lt;String&gt; input) {
      return input.isPresent() ? input.get().substring(0,7).toUpperCase() : "NOT_FOUND";
  }
  </code></pre>
  
  <p>@Aominè's answer and follow up comments addressed both parts of this question.</p>