Logo

Programming-Idioms

History of Idiom 7 > diff from v10 to v11

Edit summary for version 11 by :

Version 10

2015-08-13, 03:50:02

Version 11

2015-08-13, 03:50:31

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.length; i++) {
    T element = list[i];
    System.out.printf("Item %d = %s%n", i, element);
}
Code
for (int i = 0; i < items.length; i++) {
    T x = items[i];
    System.out.printf("Item %d = %s%n", i, x);
}
Comments bubble
Solution if the list is an array.
Comments bubble
Solution if the list is an array.