//Make an res array that is equal to a but don't contains number 0 int[] res = Arrays.stream(a).filter(x -> x != 0).toArray();