Can anybody tell me how to print the index number of elements in the ArrayList using for each looping in Java.
like @Michael's but shorter. A pet obsession I'll admit.
List list = Arrays.asList("zero", "one", "two", "three"); int index=0; for(String s : list) System.out.println((index++)+": "+s);
prints
0: zero 1: one 2: two 3: three