I have been trying to figure out a way to do this Hopefuly you'll understand my problem.
So I have a List of Lists of different data types
List<List<?>> a = [["1",100],["2",200],["5",300],["1",10],["2",20],["5",40]]
I need a list out of this list by substracting the integer values of same ID(the first element of every list) for example the result of stream should be
[["1",90],["2",80],["5",240]]
few things to be notes here 1.there will always be only 2 occurrence of every ID(index 0 (string part)). 2.the order should be maintained the id(index 0) found second should be substracted from the first.
is there any way to achieve this using stream kindly let me know
I tried this but it is not working
List<List<?>> b = a.parallelStream().map(each1 -> a.parallelStream().forEach(each2->{each1.got(0).equals(each2.get(0))? true:false;})? Arrays.asList(each2.get(0),each1.get(1)-each1.get(1)):null).collect(Collectors.toList())
As always with this type of question, the imperative approach is much easier to read and reason about:
I don't have a compiler handy so I can't test, but this should get you started.
After completing and understanding this example, you may even be able to turn it into a functional pipeline. But if you want this code to be maintainable, you probably shouldn't.