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 )
1 month 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.
🌐
Oracle
docs.oracle.com › javase › 9 › docs › api › java › util › stream › IntStream.html
IntStream (Java SE 9 & JDK 9 )
IntStream.iterate should produce the same sequence of elements as produced by the corresponding for-loop:
🌐
HowToDoInJava
howtodoinjava.com › home › java 8 › guide to intstream in java
Guide to IntStream in Java - HowToDoInJava
March 4, 2022 - IntStream.iterate(0, i -> i + 2).limit(10); //0,2,4,6,8,10,12,14,16,18 · The generate() method looks a lot like iterator(), but differs by not calculating the int values by incrementing the previous value.
🌐
Tabnine
tabnine.com › home page › code › java › java.util.stream.intstream
java.util.stream.IntStream.iterate java code examples | Tabnine
* * @param numbers Input array of numbers * @param size The chunk size * @return Smaller chunks */ public static int[][] chunk(int[] numbers, int size) { return IntStream.iterate(0, i -> i + size) .limit((long) Math.ceil((double) numbers.length ...
🌐
Medium
medium.com › @AlexanderObregon › javas-stream-iterate-method-explained-2922dfd01117
Java’s Stream.iterate() Method Explained | Medium
December 1, 2024 - Example: import java.util.stre... "B", "C") .forEach(System.out::println); } } Use Stream.iterate() for dynamic sequences where each element depends on the previous one....
🌐
GeeksforGeeks
geeksforgeeks.org › java › intstream-iterator-method-in-java
IntStream iterator() Method in Java - GeeksforGeeks
May 7, 2025 - Explanation: Here, we are using IntStream.range() method for creating a stream of integers from a start point to an end point and then we are using an iterator to iterate over the stream.
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Java 8 IntStream With Working Examples - Java Code Geeks
January 3, 2022 - A quick guide to understand primitive int representation of Stream as interface IntStream to support integer operations and with the useful examples. In this tutorial, We’ll learn how to use the IntStream in java 8 and it uses with example programs.
Find elsewhere
🌐
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.
🌐
Baeldung
baeldung.com › home › java › java streams › how to iterate over a stream with indices
How to Iterate Over a Stream With Indices | Baeldung
2 weeks ago - Let’s implement a method which iterates with indices and demonstrates this approach. Simply put, we want to get an array of Strings and only select even indexed elements: public List<String> getEvenIndexedStrings(String[] names) { List<String> evenIndexedNames = IntStream .range(0, names.length) .filter(i -> i % 2 == 0) .mapToObj(i -> names[i]) .collect(Collectors.toList()); return evenIndexedNames; }
🌐
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 › intstream-iterator-java
IntStream iterator() in Java - GeeksforGeeks
March 21, 2018 - Examples: Input: Iterator = {1, 2, 3, 4, 5} Output: {1, 2, 3, 4, 5} Input: Iterator = {'G', 'e', 'e', 'k', 's'} Output: {'G', 'e', 'e', 'k', 's'} Below are the various ways to do so: By overriding the abstract method Iterable.itera
🌐
Medium
medium.com › @ilakk2023 › 245-iterating-in-reverse-direction-using-intstream-950663d55f54
245. Iterating in reverse direction using IntStream. | by Ilakkuvaselvi (Ilak) Manoharan | Medium
April 30, 2024 - However, for larger ranges or more complex iteration requirements, IntStream.iterate provides better efficiency and flexibility. Here is an example of using IntStream: import java.util.Arrays; import java.util.HashSet; import java.util.Set; import java.util.function.BiPredicate; import java.util.stream.IntStream; public class Pet3X3Team8 { public static boolean checkConstraints(int val, int x, int y) { return val >= x && val <= y; } public static int countTeamsEast(String set, int x, int y) { Set<int[]> positions = new HashSet<>(); // Define a BiPredicate to check constraints BiPredicate<Integ
🌐
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.
🌐
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(...
🌐
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 ...
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › java › intstream-foreach-method-java
IntStream forEach() Method in Java - GeeksforGeeks
May 6, 2025 - // Java program to demonstrate // IntStream.forEach on a range import java.util.stream.IntStream; public class Geeks { public static void main(String[] args) { // Creating an IntStream from 4 to 8 (9 is exclusive) IntStream stream = IntStream.ran...
🌐
Rip Tutorial
riptutorial.com › using intstream to iterate over indexes
Java Language Tutorial => Using IntStream to iterate over indexes
Streams of elements usually do not allow access to the index value of the current item. To iterate over an array or ArrayList while having access to indexes, use IntStream.range(start, endExclusive).
🌐
Mkyong
mkyong.com › home › java8 › java 8 stream.iterate examples
Java 8 Stream.iterate examples - Mkyong.com
November 29, 2018 - int sum = Stream.iterate(new int[]{0, 1}, n -> new int[]{n[1], n[0] + n[1]}) .limit(10) .map(n -> n[0]) // Stream<Integer> .mapToInt(n -> n) .sum(); System.out.println("Fibonacci 10 sum : " + sum);