performancegroovycollections

How to create a list of random uuid with specific size of elements in groovy


Say, I want to create a list quickly which contains 1000 random UUIDs. What is the best way to accomplish this?

I went through equivalent piece of code in Java: How to create a list with specific size of elements

Tried code

List<String> generateValidations(final int count) {
        return Stream.generate(UUID.randomUUID().toString())
                .limit(count)
                .collect(Collectors.toList())
    }

But got an eror:

groovy.lang.MissingPropertyException: No such property: Stream for class: com.test.rds.specifications.ExecuteValidationsSpecification

Solution

  • Or, without a stream...

    def listOfUuids = (1..1000).collect { UUID.randomUUID().toString() }