I didn’t experience any lag whatsoever.
That is on an i5-2520M w/ dog slow integrated Intel HD 3000 graphics, 8gig ram and an SSD.
My eyes are still burning from looking at that code but what i can tell you is:
- Get rid of all System.gc() calls.
- Clean up your code a bit whole f**king lot. Spacing, indentation, …
I can’t find anything particularly sinful in there and your use of Arrayslist seemed fine tbh.
I noticed you use ArrayList.trimToSize() a lot and also inside tight loops, that’s unnecessary (you don’t gain any speed and maybe a few kilobytes of memory) but what you are doing with the ArrayLists shouldn’t kill your performance.
Just avoid constantly resizing and creating stuff, better pre-allocate a larger array, even if it wastes a few kilobyte in most situations.
If you think collision detection (Iterating over all items in your level) is killing your performance you can use techniques like spatial-partition: http://gameprogrammingpatterns.com/spatial-partition.html
This is especially easy and efficient with a 2d tile based game.