Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Benefits of "both" arraylist and linkedlist... possible in java?

Of course, I know about the performance difference between arraylist and linkedlist. I have run tests myself and seen the huge difference in time and memory for insertion/deletion and iteration between arraylist and linkedlist for a very big list.

(Correct me if i am wrong)We generally prefer arraylist over linkedlist because:

1)We practically do iterations more often than insertion/deletion. So we prefer iterations to be faster than insertion/deletion.

2)The memory overhead of linkedlist is much more than arraylist

3)There is NO way in which we can define a list as linkedlist while inserting/deleting in batch, and as arraylist while iterating. It is because arraylist and linkedlist have fundamentally different data-storage techniques.

Am I wrong about the 3rd point [I hope so :)]? Is there any possibility to have benefits of these two data structures in a single list? I guess, data structure designers must have thought about it.

like image 765
Biman Tripathy Avatar asked Nov 18 '12 19:11

Biman Tripathy


1 Answers

If you are looking for some more performant collection implementations, check out Javolution. That package provides a FastList and FastTable which may at least reduce the cost of choosing between linked lists and array lists.

like image 149
Christian Trimble Avatar answered Oct 21 '22 03:10

Christian Trimble