I was reading Kathy sierra's OCP8 guide and found a line that says:
"ArrayDeque is like an ArrayList with better performance"
Now I am confused about where to use ArrayList
and where to use ArrayDeque
.
I also know that ArrayDeque is always resized to a power of 2. On resize, the capacity is doubled, so this might be a performance hit in some cases. But I want to know which is preferable between the two.
Help is much appreciated.
i would suggest use ArrayList over ArrayDeque on below cases
Insertion and Deletion in Both Collection.
ArrayList:
Worst-case O(n) because you have to shift elements. Insertion/deletion at the end is faster because there are fewer elements to shift. If you insert when the Arraylist is full, you have to copy the elements into a new larger array, which is O(n).
ArrayDeque:
now answer is in your question. its totally depend on your requirement.after analysing you can easily predict.
for more please take a look