I have code like this
int[] array = {1, -1, 2, 3, -4};
Integer[] out = Arrays
.stream(array)
.filter(elem -> elem >= 0) // remove negatives
.boxed()
.collect(Collectors.toList())
.toArray(new Integer[array.length]);
But the filter operation leaves the negative elements in the array as null
s. Why doesn't it remove them?