I have a List of Integer say list1, and I want to get another list list2 which will contain the cumulative sum up until the current index from start. How can I do this using Str
An O(n) (works only sequentially) solution would be the following, but I don't find it very elegant. I guess it is a matter of taste
O(n)
AtomicInteger ai = new AtomicInteger(); List collect = list1.stream() .map(ai::addAndGet) .collect(Collectors.toList()); System.out.println(collect); // [1, 3, 6, 10]