0

I'm trying to make an array of random ints like this:

static int[] randomInts (int size, int randomNumberOrigin, int randomNumberBound)
{
    return ThreadLocalRandom.current()
            .ints(size, randomNumberOrigin, randomNumberBound)
            .toArray();
}

The array would be like this:

[1, 8, 4, 4, 9, 6, 0, 9, 0, 5, 3, 6, ... ]

The task is to limit the stream to the first found zero so that the array would be like this:

[1, 8, 4, 4, 9, 6, 0]

Is there an easy way to make with something like .limitByPredicate(n -> n == 0) ?

0 Answers0