Populate int[ ] array from console on 1 line with Lambda (java)

Viewed 673
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
     Object[] test = Arrays.stream(br.readLine().split(" ")).map(string -> Integer.parseInt(string)).toArray();
     System.out.println(Arrays.toString(test));
} catch (IOException E) {

}

So this code works but it returns an array of type Object[] However, what I want is to make it return an array of type int[].

does anyone have an idea of how I can accomplish that?

1 Answers
Related