I have this object:
String[] stringNum = new String[] {"1", "2", "3", "4", "5", "6", "7"};
And I'm having some trouble to understand why this works:
List<Integer> intNums = Arrays.stream(stringNum)
.map(Integer::parseInt)
.collect(Collectors.toList());
But this doesn't:
List<Integer> intNums = Arrays.stream(stringNum)
.mapToInt(Integer::parseInt)
.collect(Collectors.toList());
If I understood to correctly then both .map(Integer::parseInt)
and .mapToInt(Integer::parseInt)
should return the same IntStream
in this case to be handled by .collect(Collectors.toList())
.