foreach


A for loop uses a counter to reference the current item, so it's an easy way to operate over both the data and its index in the list: List rankings = new ArrayList <> (); for ( int i = 0; i < movies.size (); i++) { String ranking = (i + 1) + ": " + movies.get (i); rankings.add (ranking); }