you don't have to do it this way, this is typically my guideline
i normally would use a for loop with a known size and a while loop where you don't know the size until the last iteration
which is the same as I posted :)
I was writing in a simplistic form of pseudo-code, not in Java. the easiest way for him to go is a for, since he has a list and can easily determin the number of elements in it, but we can't do it all for him, now can we?
> can somebody give me some good example of how to iterate over list,
Just use an Iterator / ListIterator for iterating over a List in a implementation agnostic manner. Iterators have the benefit of being able to allow you to add / remove an element without any additional effort.
Using a simple looping construct for a LinkedList has serious performance implications since each get() walks the list till the element with the given index is found i.e. it's not a O(1) operation as in the case of an ArrayList but a O(n) operation.