I have list of objects, each object having an id. I want to group elements by their id given they are consecutive. Like, if objects are:
(id1, id1, id1, id2, id2, id3, id3, id2, id2, id4)
then groups must be:
(id1, id1, id1), (id2, id2), (id3, id3), (id2, id2), (id4)
Can this be achieved by Java Streams API?