You will want to improve your code formatting using consistent indentation. Your for loops especially are very difficult to read and it's hard to know what code is inside and what is outside of the for loop. Please edit your code above as this will help both you and us.
It sort of appears that you're removing an element from the ArrayList from within the for loop, and if so, don't do that as you'll get unexpected side effects. For one if you remove the 0th element while its looping, the next element you get an the next iteration of the loop won't be the next item in the ArrayList because the list has changed.
Edit: no you're not removing items in the loop so ignore that, but again please please fix your indenting. It shows that you respect our efforts and free time if you put in efforts to make it easier for us to read your code.