How to use IntStream in Java

3 Answers

0 votes
import java.util.stream.Stream;
import java.util.stream.IntStream;
import java.util.PrimitiveIterator;

public class MyClass {
    public static void main(String args[]) {
        IntStream istream = IntStream.of(3, 6, 9, 12, 17); 

        PrimitiveIterator.OfInt pi = istream.iterator(); 
   
        while (pi.hasNext()) { 
            System.out.println(pi.nextInt()); 
        } 
    }
}




/*
run:

3
6
9
12
17

*/

 



answered Sep 28, 2019 by avibootz
edited Nov 21, 2022 by avibootz
0 votes
import java.util.stream.Stream;
import java.util.stream.IntStream;

public class MyClass {
    public static void main(String args[]) {
        IntStream istream = IntStream.of(3, 6, 9, 12, 17); 

        istream.forEach(System.out::println);
    }
}




/*
run:

3
6
9
12
17

*/

 



answered Sep 28, 2019 by avibootz
edited Nov 21, 2022 by avibootz
0 votes
import java.util.stream.Stream;
import java.util.stream.IntStream;

public class MyClass {
    public static void main(String args[]) {
        IntStream istream = IntStream.range(2, 9);

        Stream<Integer> stream = istream.boxed();
  
        stream.forEach(System.out::println);
    }
}




/*
run:

2
3
4
5
6
7
8

*/

 



answered Nov 21, 2022 by avibootz

Related questions

2 answers 145 views
1 answer 180 views
1 answer 176 views
176 views asked May 22, 2020 by avibootz
1 answer 150 views
1 answer 163 views
163 views asked Sep 28, 2019 by avibootz
1 answer 202 views
1 answer 200 views
...