re: Introduction to Java Stream API VIEW POST


Interesting article, I need to get better at these in Java!

I'm intrigued as to the purpose of the mapToInt in the sum example here:


Why do you need that? Is numbers not already list of ints?


Hey Jamie,

I am glad you liked it!

numbers is an array of Integer's. Integer is a class in Java which simply boxs the primitive int type. Therefore I have to call intValue to get access on the actual value of the primitive type.

If you have an int array you can do this:

int[] numbers = {1, 2, 3, 4, 5};

Code of Conduct Report abuse