package com.javaprogramto.java8.streams.infinite; import java.util.List; import java.util.UUID; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; public class StreamGenerateExample { public static void main(String[] args) { // Generates the UUID Supplier<UUID> randomUUIDSupplier = () -> UUID.randomUUID(); List<UUID> uuidList = Stream.generate(randomUUIDSupplier).limit(15).collect(Collectors.toList()); System.out.println("10 random UUID list : "+uuidList); } }
Output:
10 random UUID list :
[781bce19-1dfd-4564-b220-80fb7aa850bc, a24d411a-7d5a-4447-9f5b-77f366dfd853, ccfd492e-78a4-47f7-9941-366cd60368c7, 3a97b09d-5e47-4814-8075-098ed516572d, 3ea7aaaf-04b9-4a12-b97c-e32e0ac0db80, d98690b7-696f-4355-b1e8-ce381378f490, 173d0497-dd8f-401f-8d39-30b2ddca8cf4, 7880e981-3265-4ebf-a73e-0c706c5b21f6, ac255ce3-a964-4d15-bf9c-13b5834cbc88, 6aa279ee-32b7-4e14-b689-d1586b8b124a, 0e1dd672-99d1-498d-93cf-1ddefb9bfc34, d9dd7643-83c9-44cb-a669-483e1e6c877e, 98f3018f-a7c1-4dbb-b391-8a1d2885553a, aa75f989-01e3-4b15-93ab-5096068f26a4, ad762c3b-9a66-438a-801c-8e3c48f8a223]
No comments:
Post a Comment