Logo

Programming-Idioms

History of Idiom 7 > diff from v85 to v86

Edit summary for version 86 by programming-idioms.org:
[Java] Emphasize in comments

Version 85

2020-04-24, 09:49:08

Version 86

2020-04-24, 09:49:25

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

Extra Keywords
traverse traversal
Extra Keywords
traverse traversal
Code
for (int i = 0; i < items.size(); i++) {
    T x = items.get(i);
    System.out.printf("Item %d = %s%n", i, x);
}
Code
for (int i = 0; i < items.size(); i++) {
    T x = items.get(i);
    System.out.printf("Item %d = %s%n", i, x);
}
Comments bubble
Solution if the list is a List.
Comments bubble
items is a List.