this is how I can find sum of array. p[i] - array of random integers, size 1000
sum = 0;
for (int j = 1; j < p.length; j++ )
{
sum = sum + p[j];
}
my question is how can I use multiple threads to perform it faster?
this is how I can find sum of array. p[i] - array of random integers, size 1000
sum = 0;
for (int j = 1; j < p.length; j++ )
{
sum = sum + p[j];
}
my question is how can I use multiple threads to perform it faster?
Simply:
int sum = Arrays.stream(p).parallel().sum();