Logo

Programming-Idioms

History of Idiom 7 > diff from v159 to v160

Edit summary for version 160 by reilas:
[Java] edit

Version 159

2024-11-12, 19:59:05

Version 160

2024-11-13, 17:10:55

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Variables
i,x,items
Variables
i,x,items
Extra Keywords
indices traverse traversal
Extra Keywords
indices traverse traversal
Imports
import static java.lang.System.out;
import static java.util.stream.IntStream.range;
Imports
import static java.lang.System.out;
import static java.util.stream.IntStream.range;
Code
range(0, items.length).forEach(i -> {
    out.println(i + " = " + items[i]);
});
Code
range(0, items.length).forEach(i -> {
    out.println(i + " = " + items[i]);
});
Comments bubble
There is also a `rangeClosed` method.
Doc URL
https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/util/stream/IntStream.html#range(int,int)
Doc URL
https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/util/stream/IntStream.html#range(int,int)