I'm currently learning how to use Java and my friend told me that this block of code can be simplified when using Java 8. He pointed out that the parseIntArray
could be simplified. How would you do this in Java 8?
public class Solution {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String[] tokens = input.nextLine().split(" ");
int[] ints = parseIntArray(tokens);
}
static int[] parseIntArray(String[] arr) {
int[] ints = new int[arr.length];
for (int i = 0; i < ints.length; i++) {
ints[i] = Integer.parseInt(arr[i]);
}
return ints;
}
}