Logo

Programming-Idioms

History of Idiom 7 > diff from v160 to v161

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

Version 160

2024-11-13, 17:10:55

Version 161

2024-11-15, 22:22:59

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]);
    });
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)