Creating your own class is the right way. Now for storing objects of this class ...
If you need a direct search (for example, "give me the 5th object") on objects, when you have everything, use an ArrayList . But if you just iterate over all the objects in order, you should consider a linked list .
The ArrayList class uses a primitive array, which will grow as needed to accommodate the elements you add to it. When it develops its internal structure, it needs to select a new array and copy all the original values. This can be expensive (especially with 100K elements!). You can give it its original size to give it more time before it needs to grow; but if you donβt need so much space, the internal ArrayList can waste a large chunk of memory.
Adding items to a linked list is practically worthless, because "growth" is not needed; it just adds another node to the list. But you cannot search for items by their index. You will need to start from the first element and iterate over the list into the desired element.
source share