You can't do anything like this, not without a lot of hassle. The simplest way of writing what you want would be two stages:
int max = Arrays.stream(array).max().getAsInt();
int count = (int) Arrays.stream(array).filter(i -> i == max).count();
If you insist on doing it in one pass, I'd write something like
int[] maxAndCount = Arrays.stream(array).collect(
() -> new int[2], // first max, then count
(maxAndCount, i) -> {
if (i > maxAndCount[0] || maxAndCount[1] == 0) {
maxAndCount[0] = i;
maxAndCount[1] = 1;
} else if (i == maxAndCount[0]) {
maxAndCount[1]++;
}
},
(maxAndCount1, maxAndCount2) -> {
if (maxAndCount1[0] < maxAndCount2[0]) {
maxAndCount1[0] = maxAndCount2[0];
maxAndCount1[1] = maxAndCount2[1];
} else if (maxAndCount1[0] == maxAndCount2[0]) {
maxAndCount1[1] += maxAndCount2[1];
}
});
int count = maxAndCount[1];
...but honestly, the simple two-stage version is hard to beat. (And frankly I'd expect it to perform better.)
max()return?max()returns the largest Integer in the array Stream.