These methods set all elements of the specified array, using the provided generator function to compute each element.
package com.logicbig.example.arrays;
import java.util.Arrays;
public class SetAllExample {
public static void main(String... args) {
int[] arr = new int[10];
Arrays.setAll(arr, (index) -> 1 + index);
System.out.println(Arrays.toString(arr));
}
}
Output
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
package com.logicbig.example.arrays;
import java.util.Arrays;
public class SetAllExample2 {
public static void main(String... args) {
String[] arr = new String[10];
Arrays.parallelSetAll(arr, (index) -> Integer.toString(index + 1));
System.out.println(Arrays.toString(arr));
}
}
Output
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]