Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to make it so that no more than 5 units can be stacked on a tile. I have a Tile class that creates each tile's preferences. Should I store the units in an array or arraylist in this class?

share|improve this question

Choosing a data structure will depend on what other features you want to support. In this case, you may as well use the ArrayList since it's easier to work with and more flexible.

It would be best to just store a reference to the unit in the tile, and have the unit objects stored elsewhere.

share|improve this answer
Up to 5 units is so trivial though. Either will do. – Sidar Jan 13 '13 at 12:34
I agree @Sidar. I say ArrayList because it's much easier for a new developer to handle. With easy functions like add and remove. – Byte56 Jan 13 '13 at 20:02

Based on the nature of your question a Stack be optimal, however it is last in first out so I don't know if that would fit your requirements, otherwise you could also use a queue. If order doesn't matter to you then use ArrayList, it is generally the most efficient (good comparison to linkedlist here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.