Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the fastest java collection for retrieving large numbers of DTOs?

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).

like image 896
josh-cain Avatar asked Sep 27 '12 19:09

josh-cain


People also ask

Which collection is best for performance Java?

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.

Which collection class gives faster iteration and fast random access?

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.

Which is faster array or collection?

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.


1 Answers

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.

like image 167
Christof Aenderl Avatar answered Oct 23 '22 09:10

Christof Aenderl