Java Arrays - parallelSetAll() Method
The java.util.Arrays.parallelSetAll() method is used to set all elements of the specified array, in parallel, using the provided generator function to compute each element. If the generator function throws an exception, an unchecked exception is thrown from parallelSetAll and the array is left in an indeterminate state.
Syntax
public static void parallelSetAll(long[] array, IntToLongFunction generator)
Parameters
array |
Specify array to be initialized. |
generator |
Specify a function accepting an index and producing the desired value for that position. |
Return Value
void type.
Exception
Throws NullPointerException, if the generator is null.
Example:
In the example below, the java.util.Arrays.parallelSetAll() method is used to set all elements of the given array, in parallel, using the given generator function.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating a long array long Arr[] = {1, 2, 3, 4, 5}; //printing array System.out.print("Arr contains:"); for(long i: Arr) System.out.print(" " + i); //set all elements of the array to the square //of itself using generator function Arrays.parallelSetAll(Arr, e->{ return Arr[e]*Arr[e]; }); //printing array System.out.print("\nArr contains:"); for(long i: Arr) System.out.print(" " + i); } }
The output of the above code will be:
Arr contains: 1 2 3 4 5 Arr contains: 1 4 9 16 25
❮ Java.util - Arrays