Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Can anybody tell me with good example that performance between arraylist and linkedlist?who is faster? and in which situation to use arraylist and linked List?

I searched on net but couldn't find proper solution with example,
If anyone knows or If anyone found use full info on net then also it is most welcome.

Thank you in advance.
Posted

Then i should say you can't search efficiently.Look at these which will clear you most:
What is the difference between LinkedList and ArrayList, and when to use which one?[^]
When to use a linked list over an array/array list?[^]
 
Share this answer
 
I agree with Ridoy's response: you have not really searched even CodeProject itself.

To really get a meaningful answer to your question, first, you have to make the question meaningful.

Specifically, real-world comparisons of performance of different data structures (assuming you have a choice) need to be based on their most frequent (modal) uses, and other issues like scalability, memory usage and constraints, etc.

If you most frequently are adding things to a data structure, and pulling out the first one added (fifo), or the last one added (lifo): that's one case. If you are frequently doing random insertions and deletions anywhere in: collection/list/linked-list/queue/fifo- or lifo- stacks/circular-list/named pipes/btree, and so on: that's another.

Depending on your needs, you may, or may not, need to use Generic data-structures offered by .NET's System.Collections.Generic namespace: [^], such as Queue<T> [^].

Perhaps all you need are 'ArrayList and other data-structures found in System.Collections: if you clarify your question with more specific information about what your goals are, you will, very possibly, get good advice, on which direction to follow.

In any case, I highly recommend this excellent six-part overview of .NET data-structures: "An Extensive Examination of Data Structures" on MSDN (written by Scott Mitchell of 4guysfromrolla.com): [^]. The series was written long ago (in internet time), but I think it is "worth its weight in gold." It does cover Generic Types.
 
Share this answer
 
v2
Comments
Joezer BH 1-Sep-13 6:51am    
5ed!
In addition to other answers: you should not use ArrayList. This collection was rendered obsolete as early as of .NET Framework 2.0, when generics were introduced. You should use, without any performance loss, the generic class System.Collections.Generic.List<>. Non-generic ArrayList requires potentially dangerous type casts. It is not formally marked as obsolete just because there is nothing wrong in it if it is used in well debugged legacy assemblies, but for new development using non-specialized non-generic collection classes simply makes no sense.

—SA
 
Share this answer
 
ArrayList is more store memory efficient, only data (and extra space if it's Capacity has been set larger than it's Length) and fastest for random (indexed) read/write accesses. There is a large memory copy overhead when inserting new elements before the list end or in case of adding more elements at the end when no more free space is available in the list and it's capacity must me enlarged. The same hannpens when removing elements from the list.

If the list should work like a FIFO (First In-First Out), LinkedList will usually offer better performance than ArrayList.

You may write a small application to evaluate wich one performs best and under what circumstances (sharing the results could be great for all). For one small elements count you will probably not see much difference in performance.

For making your code easier to read and removing lots of nasty typecastings try using the List<t></t> template.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900