You can convert all elements of the array Stringto intand store them in the array intas follows:
public static final void main(String[] args) {
String input = "1 2 5 17 23 12 5 72 123 74 13 19 32";
String[] strAr = input.split(" ");
int[] output = parseIntArray(strAr);
}
private static int[] parseIntArray(String[] strAr) {
int[] output = new int[strAr.length];
for (int i = 0; i < strAr.length; i++) {
output[i] = Integer.parseInt(strAr[i]);
}
return output;
}
How can you write a method parseIntArray(String[])in a map reduction method in Java?
I heard that there is an easy way to do this using lambdas in Java 8. Was there also a way to reduce the map size for this to Java 8? I know that these are two questions in one; however, I believe that they are so closely related that it is better for the community to have both of these answers on the same page.
source
share