Is there a simple way to split a list into sublists by grouping only repeated elements that are adjacent to each other?
Simple example with the folowing list of strings:
Input: [RED,RED,BLUE,BLUE,BLUE,GREEN,BLUE,BLUE,RED,RED]
Output: [[RED,RED],[BLUE,BLUE,BLUE],[GREEN],[BLUE,BLUE],[RED,RED]]
If I use groupingBy from java streams all elements which are equal will end up in the same sublist, which I want to avoid. Any ideas?