I have a requirement to store around 100000 - 200000 records in a collection object. As of now, I am planning to use ArrayList, but I am interested to know the best way to store such a huge list.
Can any one of you help me come up with some thoughts on how to store large amounts of data into Collection? Which one is efficient, affordable in terms of performing well when it lands up in place?
ArrayList: Grows dynamically by allocating new memory chunks, potentially causing fragmentation. Is there any way we can define the size while creating the object itself? Is it the correct way to define ? Also do I need to change the java heap size ?
Is there any other data structure I should consider?
Note - I have decided to go with arraylist as order and index does not matter. I am fine with random access. I just want to know what are the best practice and other alternative approach.
Handling a large number of records efficiently involves choosing the right data structure. Here are simplified options:
ArrayList<Type> list = new ArrayList<>(initialCapacity);