Logo

Programming-Idioms

History of Idiom 7 > diff from v5 to v6

Edit summary for version 6 by :

Version 5

2015-08-04, 16:38:01

Version 6

2015-08-04, 16:38:34

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