Logo

Programming-Idioms

History of Idiom 7 > diff from v149 to v150

Edit summary for version 150 by reilas:
[Java] Readibility

Version 149

2024-11-03, 21:37:29

Version 150

2024-11-03, 21:38:33

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
Imports
import static java.lang.System.out;
Code
for (int i = 0; i < items.size(); i++) {
    T x = items.get(i);
    System.out.printf("Item %d = %s%n", i, x);
}
Code
int i, n;
for (i = 0, n = items.size(); i < n; ++i)
    out.println(i + " = " + items.get(i));
Comments bubble
items is a List.
Comments bubble
items is a List.