Is there any significant difference (in performance or best practices) between those two stream creation methods?
int[] arr2 = {1,2,3,4,5,6};
Arrays.stream(
IntStream.boxed() uses Integer.valueOf(int) which is an optimised version* of Integer(int).
Internally, boxed()
is defined as mapToObj(Integer::valueOf)
.
*this method should generally be used in preference to the constructor
Integer(int)
, as this method is likely to yield significantly better space and time performance by caching frequently requested values.The Javadoc of Integer.valueOf(int)