This has nothing to do with I/O, so I'm stealing this to
Java in General.
You are calling remove but you probably still assume that the size has remained the same. However, when you remove an element the size of course changes. A very common mistake is the following:
This will remove every other element; you first remove element 0, but old element 1 becomes element 0. You then remove element 1 which was previously element 2, etc.
Can you show us your loop?