Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,855 questions

51,776 answers

573 users

How to use Stream.iterate in Java

2 Answers

0 votes
import java.util.stream.Stream;

public class MyClass {
    public static void main(String args[]) {
        Stream.iterate(0, n -> n + 1)
                .limit(4)
                .forEach(val -> System.out.println(val));
    }
}



/*
run:

0
1
2
3

*/

 



answered Sep 28, 2019 by avibootz
0 votes
import java.util.stream.Stream;
 
public class MyClass {
    public static void main(String args[]) {
        Stream.iterate(0, n -> n + 1)
                .filter(val -> val % 2 == 0) 
                .limit(7)
                .forEach(val -> System.out.println(val));
    }
}
 
 
 
/*
run:
 
0
2
4
6
8
10
12
 
*/

 



answered Sep 28, 2019 by avibootz

Related questions

1 answer 125 views
3 answers 124 views
124 views asked Mar 14, 2023 by avibootz
1 answer 83 views
83 views asked Mar 11, 2023 by avibootz
1 answer 206 views
2 answers 114 views
114 views asked Oct 5, 2023 by avibootz
...