I have two Tables like:
Table<Long,String,Integer> tableOne
Table<Long,String,Integer> tableTwo
How can I merge the two tables where the values are summed(if needed)?
So as a result I would get a
Table<Long,String,Integer> sumTable
For example I have the following values:
in tableOne:
1L Fruits 20
2L Fruits 30
2L Vegetables 15
3L Vegetables 10
in tableTwo
2L Fruits 10
2L Vegetables 40
3L Fruits 15
4L Vegetables 35
so the sum would be:
1L Fruits 20
2L Fruits 30 + 10 = 40
2L Vegetables 15 + 40 = 55
3L Vegetables 10
3L Fruits 15
4L Vegetables 35
I would appreciate a Java8 stream-way solution, but a classical would be also acceptable.
You could use Tables.toTable:
Output