Actually range is ideal for this.

IntStream.range(0, 100).filter(x -> x % 3 == 0); //107,566 ns/op [Average]

Edit: Holgers's solution is the fastest performing solution.

Since the following lines of code

IntStream.range(0, 100).filter(x -> x % 3 == 0).forEach((x) -> x = x + 2); 

IntStream.range(0, 100 / 3).map(x -> x * 3).forEach((x) -> x = x + 2); 

int limit = ( 100 / 3 ) + 1; 
IntStream.iterate(0, n -> n + 3).limit(limit).forEach((x) -> x = x + 2);

show these benchmark results

Benchmark                 Mode  Cnt    Score    Error  Units
Benchmark.intStreamTest   avgt    5  485,473 ± 58,402  ns/op
Benchmark.intStreamTest2  avgt    5  202,135 ±  7,237  ns/op
Benchmark.intStreamTest3  avgt    5  280,307 ± 41,772  ns/op
Answer from JasperJ on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › stream › IntStream.html
IntStream (Java Platform SE 8 )
3 weeks ago - Returns an infinite sequential ordered IntStream produced by iterative application of a function f to an initial element seed, producing a Stream consisting of seed, f(seed), f(f(seed)), etc.
🌐
Exercism
exercism.org › tracks › java › exercises › collatz-conjecture › approaches › intstream-iterate
Explore the 'IntStream.iterate()' approach for Collatz Conjecture in Java on Exercism
import java.util.stream.IntStream; class CollatzCalculator { long computeStepCount(int start) { if (start < 1) { throw new IllegalArgumentException("Only positive integers are allowed"); } return IntStream.iterate(start, num -> num != 1, num -> (num & 1) == 1 ?
🌐
Oracle
docs.oracle.com › javase › 9 › docs › api › java › util › stream › IntStream.html
IntStream (Java SE 9 & JDK 9 )
Returns a sequential ordered IntStream produced by iterative application of the given next function to an initial element, conditioned on satisfying the given hasNext predicate.
🌐
GeeksforGeeks
geeksforgeeks.org › java › intstream-foreach-method-java
IntStream forEach() Method in Java - GeeksforGeeks
May 6, 2025 - The IntStream forEach() method in Java is a terminal operation that performs a given action on each element of the stream. It is commonly used to iterate through primitive int values in a functional style introduced in Java 8.
🌐
Tabnine
tabnine.com › home page › code › java › java.util.stream.intstream
java.util.stream.IntStream.iterate java code examples | Tabnine
public static String[] chop(String input, int step) { if (input == null || input.length() == 0) { return EMPTY_ARRAY; } if (step == 0) { return new String[]{input}; } int strLength = input.length(); int iterations = strLength % step == 0 ? strLength / step : strLength / step + 1; return IntStream.iterate(0, i -> i + step) .limit(iterations) .mapToObj(i -> input.substring(i, (i + step) < strLength ?
🌐
Medium
medium.com › @AlexanderObregon › javas-stream-iterate-method-explained-2922dfd01117
Java’s Stream.iterate() Method Explained | Medium
December 1, 2024 - The Stream.iterate() method is a great tool for generating dynamic sequences and handling infinite streams in Java. By understanding its mechanics, leveraging lazy evaluation, and exploring its use cases, you can effectively integrate it into ...
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › java.base › java › util › stream › IntStream.html
IntStream (Java SE 21 & JDK 21)
January 20, 2026 - Returns a sequential ordered IntStream produced by iterative application of the given next function to an initial element, conditioned on satisfying the given hasNext predicate.
Find elsewhere
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › util › stream › IntStream.html
IntStream (Java SE 11 & JDK 11 )
January 20, 2026 - Returns a sequential ordered IntStream produced by iterative application of the given next function to an initial element, conditioned on satisfying the given hasNext predicate.
🌐
GeeksforGeeks
geeksforgeeks.org › java › intstream-iterator-method-in-java
IntStream iterator() Method in Java - GeeksforGeeks
May 7, 2025 - This avoids the need for converting the primitive types into objects. The iterator() method in IntStream is a terminal operation that gives us an iterator, and with the help of this iterator, we can iterate over the elements of the stream.
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › util › stream › IntStream.html
IntStream (Java SE 17 & JDK 17)
January 20, 2026 - Returns a sequential ordered IntStream produced by iterative application of the given next function to an initial element, conditioned on satisfying the given hasNext predicate.
🌐
Oracle
docs.oracle.com › en › java › javase › 26 › docs › api › java.base › java › util › stream › IntStream.html
IntStream (Java SE 26 & JDK 26)
3 weeks ago - Returns a sequential ordered IntStream produced by iterative application of the given next function to an initial element, conditioned on satisfying the given hasNext predicate.
🌐
GeeksforGeeks
geeksforgeeks.org › intstream-iterator-java
IntStream iterator() in Java - GeeksforGeeks
March 21, 2018 - IntStream range(int startInclusive, ... Parameters : IntStream : A sequence of primitive ... Given an Iterator, the task is to convert it into Iterables in Java....
🌐
TutorialsPoint
tutorialspoint.com › intstream-iterator-method-in-java
IntStream iterator() method in Java
import java.util.*; import java.util.stream.IntStream; public class Demo { public static void main(String[] args) { IntStream intStream = IntStream.of(15, 40, 55, 70, 95, 120); PrimitiveIterator.OfInt primIterator = intStream.iterator(); while (primIterator.hasNext()) { System.out.println(primIterator.nextInt()); } } }
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Java 8 IntStream With Working Examples - Java Code Geeks
January 3, 2022 - In this tutorial, We’ll learn how to use the IntStream in java 8 and it uses with example programs.
🌐
HowToDoInJava
howtodoinjava.com › home › java 8 › guide to intstream in java
Guide to IntStream in Java - HowToDoInJava
March 4, 2022 - The generate() method looks a lot like iterator(), but differs by not calculating the int values by incrementing the previous value. Rather an IntSupplier is provided which is a functional interface is used to generate an infinite sequential unordered stream of int values. Following example create a stream of 10 random numbers and then print them in the console. IntStream stream = IntStream .generate(() -> { return (int)(Math.random() * 10000); }); stream.limit(10).forEach(System.out::println);
🌐
Baeldung
baeldung.com › home › java › java streams › java intstream conversions
Java IntStream Conversions | Baeldung
January 8, 2024 - First, let’s create an infinite stream of integers starting at 0 and iterating by adding 2 to each element. Immediately after that, we need to add an intermediate operation limit in order to make this operation, somehow, terminating. Finally, let’s use the terminating operation collect to gather this Stream to an array. This is a straight-forward way of generating an array of ints. Let’s convert now an IntStream to a List of Integers.
🌐
Oracle
docs.oracle.com › javase › 10 › docs › api › java › util › stream › IntStream.html
IntStream (Java SE 10 & JDK 10 )
Returns a sequential ordered IntStream produced by iterative application of the given next function to an initial element, conditioned on satisfying the given hasNext predicate.
🌐
Straub
straub.as › java › history › java8 › intstreams.html
IntStreams
IntConsumer printInt = i -> System.out.print(i + " "); IntFunction<? extends IntStream> mapper = i -> IntStream.iterate(i, k -> k).limit(3) ; IntStream sequence = IntStream.rangeClosed(1, 5).flatMap(mapper); sequence.forEach(printInt);