We can use any of these (includes List, ArrayList, Dictionary, Hashtable, Stack, Queue) to hold value or hold reference to other objects as a collection.
But, my question is which one is used when?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Lists
Lists allow duplicate items, can be accessed by index, and support linear traversal.
ArrayList – An array-based list that doesn’t support generic types. It does not enforce type safety and should generally be avoided.
List – An array list that supports generic types and enforces type-safety. Since it is non-contiguous, it can grow in size without re-allocating memory for the entire list. This is the more commonly used list collection.
Hashes
Hashes are look-ups in which you give each item in a list a “key” which will be used to retrieve it later. Think of a hash like a table index where you can ask questions like “I’m going to find this object by this string value. Duplicate keys are not allowed.
HashTable – A basic key-value-pair map that functions like an indexed list.
Dictionary – A hashtable that supports generic types and enforces type-safety.
Queues
Queues control how items in a list are accessed. You typically push/pop records from a queue in a particular direction (from either the front or back). Not used for random access in the middle.
Stack – A LIFO (last in, first out) list where you push/pop records on top of each other.
Queue – A FIFO (first in, first out) list where you push records on top and pop them off the bottom.