Issue
I want to generate a mock List<UUID>
and fill it using random UUID's. However, I am not sure if there is a more proper way instead of the following approach by creating list and adding items.
List<UUID> uuidList = new ArrayList<>();
uuidList.add(UUID.randomUUID());
uuidList.add(UUID.randomUUID());
uuidList.add(UUID.randomUUID());
So, is there a better way?
Solution
You can use Java8 streams here.
List<UUID> uuidList = Stream.generate(UUID::randomUUID)
.limit(3)
.collect(Collectors.toList());
This will generate 3 random UUIDs, for more, just change the limit
.
Answered By - geobreze