Piet Souris wrote:If the average distance between end index and start index = 2.000.000, and there are 100.000 lines, then in total you are doing 2 * 10^11 additions. If java does 10^7 additions per second, then the whole operation will take 20.000 seconds...
Suppose I have the index-segments [a. b] and [c, d], and I know that for index i array[i] is maximal for all indices in [a, b], and likewise j is the index in [c, d] where array[j] is maximal, then what can I say about the maximum when I add X to all array elements with indices in [a, b] and Y to all elements with index in [c, d]? Beware that [a, b] and[c, d] may overlap.
A Stream is intended to operate on the whole of a source (that source might be a List), so a Stream might not work at all well if you are only dealing with a part of the List. Another thing is that the Stream will create a new List which you will later have to incorporate in the old List (or array or whatever), so Junilu is right that a loop is probably easier to use.
Junilu Lacar wrote:. . . you don't need Java 8 and streams . . .
Piet Souris wrote:Well, let me try to be a bit less cryptic.