Not so recently I’ve published a game that is written entirely in Java on Android platform. Currently I’m trying to get as much of the performance as possible. It seems that the problem in my game’s case is that I’m using more too often ArrayList container in places where Map could be better suited. To explain myself I did it because I was afraid of dynamic memory allocations that would be triggered behind the scene (Map/Tree structures on Android). Maybe there is some sort of structure on Android/Java platform I don’t know about, which will provide me with fast searching results and additionally will not allocate dynamically extra memory when adding new elements?
UPDATE:
For example I’m using an ArrayList structure for holding most of my game’s Particles. Of course removing them independently (not sequentially) is a pain in the b**t as the system needs to iterate through the whole container just to remove one entity object (of course in the worst case scenario).
I wouldn’t worry about slowdown because of memory allocation unless you specifically find it to be an issue. Memory allocation isn’t really the cause of slowdowns in Android games, it’s when the GC runs that’s usually the problem. Unless you are inserting and deleting from the Map very often, you might not have to worry about the allocations.
Update:
Instead of using a Map, you might want to consider just marking particles as “dead” when you no longer need them and using that flag to skip over them in your update iteration. Store the references to the dead particles in a new deadParticles ArrayList, and just take one out from that list when you need a new one. That way the you have instant access to particles when you need them.