Java 8: Infinite Stream of UUIDs 📎
import java.util.UUID;
import java.util.stream.Stream;
import org.junit.Test;
@Test
public void infiniteUUIDStream() {
Stream<String> uuidStream = Stream.
generate(UUID::randomUUID).
map(u -> u.toString());
uuidStream.
limit(10).
forEach(System.out::println);
}
Now you only need a few asserts
to verify that the infinite Stream
only comprises unique values :-)
See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.