How to combine consecutive similar objects that are in a Java Stream?
Till now I could not find a good solution, so I hope you can help.
Suppose we have a class like the following:
class Someclass {
String type;
int count;
}
When having a Stream { "a", 1 }, { "a", 2}, { "b", 4}, { "b", "5" } and that needs to be processed as { "a", 3 }, { "b", 9 }.
Combining means of course, adding the counts for the objects with the same type.
How to do?
question from:https://stackoverflow.com/questions/65943016/combine-similar-elements-in-a-java-stream