I know this can be changed depending on threads etc., but I am looking for at least general guidance and benchmarks. Also, I need to maintain a standard Java collection (no third-party libraries).
If you set the initial capacity to a higher value (don’t know what you call a large number), then it will be more Fast, because it reduces the number of incremental reallocations.
Any other collection has some kind of overhead, such as finding a hash code or synchronization.
< p>I’m returning a large number of collections from DTO objects and want to know if anyone can point me in the right direction. Any type of collection will do, but I don’t know which one is best for the task of returning a large number of objects.
p>
I know this can be changed based on threads etc., but I am looking for at least general guidance and benchmarks. Also, I need to maintain a standard Java collection (no third-party libraries).
< p>
As indisputable: If you need a simple collection, then ArrayList should perform well, because it is based on an array and it is fast to use system functions by definition.
p>
If you set the initial capacity to a higher value (don’t know what you call a large number), then it will be faster because it will reduce the number of incremental reallocations.
Any Other collections have some kind of overhead, such as finding a hash code or synchronization.