BAEL-669 test of an infinite stream (#1126)
* BAEL-669 test of an infinite stream * BAEL-699 example of custom type infinite stream * BAEL-699 do..while stream way * BAEL-669 generate stream of random uuids
This commit is contained in:
committed by
Grzegorz Piwowarek
parent
4aaefd39df
commit
f772286896
@@ -0,0 +1,27 @@
|
||||
package com.baeldung.stream;
|
||||
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class InfiniteStreams {
|
||||
public static void main(String[] args) {
|
||||
doWhileOldWay();
|
||||
|
||||
doWhileStreamWay();
|
||||
|
||||
}
|
||||
|
||||
private static void doWhileOldWay() {
|
||||
|
||||
int i = 0;
|
||||
while (i < 10) {
|
||||
System.out.println(i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
private static void doWhileStreamWay() {
|
||||
Stream<Integer> integers = Stream.iterate(0, i -> i + 1);
|
||||
integers.limit(10).forEach(System.out::println);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user