I have a Stream<Set<Integer>> intSetStream
.
I can do this on it...
Set<Integer> theSetWithTheMax = intSetStream.max( (x,y)->{ return Integer.compare( x.size(), y.size() ); } ).get( );
...and I get a hold of the Set<Integer>
that has the highest number of Integer
elements in it.
That's great. But what I really need to know is, is it the 1st Set
in that Stream
that's the max? Or is it the 10th Set
in the Stream
? Or the i
th Set
? Which one of them has the most elements in it?
So my question is: Is there some way — using the Stream API — that I can determine "It was the i
th Set
in the Stream
of Set
s that returned the largest value of them all, for the Set.size( )
call"?
The best solution I can think of, is to iterate over the Stream<Set<Integer>>
(using intSetStream.iterator()
) and do a hand-rolled max( )
calculation. But I'm hoping to learn a more Stream
-y way to go about it; if there is such a thing.
takeWhile
anddropWhile
which only work for ordered streams. – Placida