Java Stream Iterating Example
package
streamconcept;
import
java.util.stream.Stream;
public class
StreamIterateExample {
public static void
main(String[] args) {
Stream.iterate(1, n->n+1)
.limit(10)
.forEach(System.out::println);
}
}
o/p:--------------------
1
2
3
4
5
6
7
8
9
10
package
streamconcept;
import
java.util.stream.Stream;
public class StreamIterateExample {
public static
void main(String[] args) {
Stream.iterate(1, n->n+1)
.filter(n->n%4==0)
.limit(10)
.forEach(System.out::println);
}
}
o/p:-----------------
4
8
12
16
20
24
28
32
36
40
No comments:
Post a Comment