I've got a java.util.stream.Stream containing key value pairs like:
<1,3> <1,5> <3,1> <4,2> <4,7> <4,8>
Now I would like to merge all entries, which have got the same key:
<1,[3,5]> <3,[1]> <4,[2,7,8]>
The data is already sorted, so only consecutive datasets have to be merged.
Now I'm searching for a way to transform the the content of the stream like above, without loading all datasets into memory.
I'd prefer to get a java.util.stream.Stream as result with a different object type containing a list of values instead of a single value.
My only approach is a custom iterator, which performs the merge, but it seems to be pretty ugly to convert to an iterator and back to stream.
What is the best approach for it?