Imagine we know the size of the list and want to go through every fifth element in it only. I think if I do that with ArrayList, like below:
List<Item> l = new ArrayList<Item>();
for (int i = 0; i < l.size(); ) {
Item item = l.get(i);
i += 5;
}
it will indirectly iterate through every element of the list up to i each time I call l.get(i) which is stupid. Is there any way to access only every fifth element? Maybe LinkedList? Could you please give me an example on how to use the ListIterator for that purpose?
for (int i = 0; i < l.size(); i += 5) {would be more readable.i++.