title: Optional variable take action based on its value
body: <p>I have a method which takes an Optional parameter and returns a list. I'll populate the list based on whether the Optional parameter is empty or not. What's the most accepted/standard way if any to write the following</p>
  <blockquote>
  <pre><code>public List&lt;ProjectDTO&gt; getProjects(Optional&lt;String&gt; analystId) {
      List&lt;ProjectDTO&gt; projects = new ArrayList&lt;&gt;();
  
      analystId.ifPresentOrElse(
              t -&gt; projects.addAll(getProjectsByAnalyst(analystId)),
              () -&gt; projects.addAll(getAllProjects())
      );
  
      return projects;
  }
  </code></pre>
  </blockquote>
  <p>This code works, however I was wondering if there's a better way to do it</p>