Skip to content

Commit f9ba789

Browse files
committed
Use Stream.generate for create random numbers stream
1 parent 08c0453 commit f9ba789

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

app/src/main/java/com/annimon/java8streamexample/MainActivity.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ private void action(String action) {
143143
break;
144144
case "random":
145145
final Random rnd = new Random();
146-
stream = Stream.ofRange(0, 10000)
147-
.map(i -> String.valueOf(rnd.nextInt(100)))
146+
stream = Stream.generate(() -> rnd.nextInt(100))
147+
.limit(10000)
148+
.map(String::valueOf)
148149
.map(s -> new Word(s, ""));
149150
break;
150151
}

0 commit comments

Comments
 (0)