I'm returning large numbers of collections from a DTO object and was wondering if anyone could point me in right direction. Any type of collection will do, but I don't know which one is best suited for the task of returning a large number of objects.
I know this can change based on threading and the like, but I'm at least looking for general guidance and benchmarks. Also, I'm required to stay within standard Java collections (no third-party libraries).
The ArrayDeque class is often the best choice for managing a deque. However, in some cases, a LinkedList will be faster. If performance is important, experiment to see if LinkedList performs better in your application. LinkedList: The LinkedList class can be used to organize objects into a deque.
TreeSet Class It uses a Tree structure to store elements. It contains unique elements only like HashSet. It's access and retrieval times are quite fast.
Arrays due to fast execution consumes more memory and has better performance. Collections, on the other hand, consume less memory but also have low performance as compared to Arrays. Arrays can hold the only the same type of data in its collection i.e only homogeneous data types elements are allowed in case of arrays.
As irreputable says: If you need a simple collection, than ArrayList should perform good because it is based on an Array which is fast by definition using the System functions.
If you set the initial capacity to a higher value (don't know what you call a large number), than it will be even faster because it reduces the amount of incremental reallocation.
Any other collection has some kind of an overhead like looking for hashcodes or beeing synchronized.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With