Filter values from a list based on priority : <p>I have a list of valid values for a type:</p>

<pre><code>Set&lt;String&gt; validTypes = ImmutableSet.of("TypeA", "TypeB", "TypeC");
</code></pre>

<p>From a given list I want to extract the first value which has a valid type. In this scenario I would write something of this sort:</p>

<pre><code>public class A{
    private String type;
    private String member;
}

List&lt;A&gt; classAList;
classAList.stream()
    .filter(a -&gt; validTypes.contains(a.getType()))
    .findFirst();
</code></pre>

<p>However I would like to give preference to <code>TypeA</code>, i.e. if <code>classAList</code> has <code>TypeA</code> and <code>TypeB</code>, I want the object which has <code>typeA</code>. To do this one approach I've is:</p>

<pre><code>Set&lt;String&gt; preferredValidTypes = ImmutableSet.of("TypeA");
classAList.stream()
    .filter(a -&gt; preferredValidTypes.contains(a.getType()))
    .findFirst()
    .orElseGet(() -&gt; {
        return classAList.stream()
        .filter(a -&gt; validTypes.contains(a.getType()))
        .findFirst();
    }
</code></pre>

<p>Is there a better approach? </p>
