title: Java contains vs anyMatch behaviour
body: <p>So if I have a <code>Name</code> object and have an <code>ArrayList</code> of type <code>Name</code> (<code>names</code>), and I want to ascertain whether my list of names contains a given <code>Name</code> object (<code>n</code>), I could do it two ways:</p>
  <pre><code>boolean exists = names.contains(n);
  </code></pre>
  <p>or</p>
  <pre><code>boolean exists = names.stream().anyMatch(x -&gt; x.equals(n));
  </code></pre>
  <p>I was considering if these two would behave the same and then thought about what happens if n was assigned <code>null</code>?</p>
  <p>For contains, as I understand, if the argument is <code>null</code>, then it returns <code>true</code> if the list contains <code>null</code>. How would I achieve this <code>anyMatch</code> - would it be by using <code>Objects.equals(x, n)</code>?</p>
  <p>If that is how it works, then which approach is more efficient - is it <code>anyMatch</code> as it can take advantage of laziness and parallelism?</p>