I am trying to use lambda expressions to convert a String array to an Integer array.
I have provided my code below, along with a brief description of what I have tried so far:
String [] inputData = userInput.split("\\s+");
Integer [] toSort = new Integer [] {};
try {
toSort = Arrays.asList(inputData).stream().mapToInt(Integer::parseInt).toArray();
}catch(NumberFormatException e) {
System.out.println("Error. Invalid input!\n" + e.getMessage());
}
The lamba expression I have above is one which maps to an int array, which is not what I want, upon compiling this code I get the following error message:
BubbleSort.java:13: error: incompatible types: int[] cannot be converted to Integer[]
toSort = Arrays.asList(inputData).stream().mapToInt(Integer::parseIn
t).toArray();
^
1 error
Is there a simple way which allows me to use lambdas, or other means, to get from a String array to an Integer array?