Count in single pass multiple items using java 8 stream
<p>Suppose I have the following class:</p>

<pre><code>class Z {
    X x;
    Y y;
}
</code></pre>

<p>And I have a list of Z elements. I want to count in a single pass how many elements have in their x field the value x1, and how many have in their y field the value y1.</p>

<p>Using a loop it is straight forward:</p>

<pre><code>int countOfx1 = 0;
int countOfy1 = 0;
for (Z z: list) {
    if (z.x == x1) {
        countOfx1++
    }
    if (z.y == y1) {
        countOfy1++
    }
 }
</code></pre>

<p>Can it be done as simply using streams?</p>