Logo

Programming-Idioms

History of Idiom 7 > diff from v11 to v12

Edit summary for version 12 by :

Version 11

2015-08-13, 03:50:31

Version 12

2015-08-13, 03:50: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

Code
for (int i = 0; i < list.size(); i++) {
    T element = list.get(i);
    System.out.printf("Item %d = %s%n", i, element);
}
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
Solution if the list is a List.