Logo

Programming-Idioms

History of Idiom 7 > diff from v4 to v5

Edit summary for version 5 by :

Version 4

2015-08-04, 16:37:51

Version 5

2015-08-04, 16:38:01

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);
}
Comments bubble
Solution if the list is an array.