Suppose I have the following class:

```
class Z {
    X x;
    Y y;
}

```

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.

Using a loop it is straight forward:

```
int countOfx1 = 0;
int countOfy1 = 0;
for (Z z: list) {
    if (z.x == x1) {
        countOfx1++
    }
    if (z.y == y1) {
        countOfy1++
    }
 }

```

Can it be done as simply using streams?