There are a couple problems that I see here. But the main one that I would look into is the fact that you are using an ArrayList Collection object and using it like a java array, but then you are mixing in Collection methods such as the remove which then changes the size and index parameters. Which then you try to compensate by readjusting the size. This makes the problem you are trying to solve more complex than it needs to be. There is a rule that you might want to read up on called KISS.
The only way I could get this even to run was to change line 31 from 'for (int i = size; i > 0 ;i--)' to 'for (int i = size - 1; i > 0 ;i--)'. Once I did that I did not have any problems running the program. However, the results were inaccurate. The autoboxing worked just fine. I only had problems with array index out of bounds, but I fixed that by changing line 31.
Hope this helps.