vendredi 25 septembre 2015

Limit an intStream with a condition [duplicate]

This question already has an answer here:

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 a way?




Aucun commentaire:

Enregistrer un commentaire