By "the amount is unknown" I mean that at the time of creation of whatever data structure I use to store them in, I don't know how many objects there will end up being to store. Once I have all these objects, I want to be able to iterate through all of them, and it doesn't matter what order I visit them in. I'm wondering what would be the most efficient (in time and space, but mostly time) way to go about doing this in java.
I do have a cap on the max number of objects that there will be in the thing, so I was considering just making an array of this size. But I didn't want to waste space, and the array could end up being more than twice as big as the number of elements that actually get stored in it.
I was also considering a LinkedList, because I thought maybe it would be more efficient to iterate through it than having to create an iterator from something else like a hashmap and iterate through that. But I don't know how expensive it is to create an iterator from various java data structures.
So, any ideas?