Collection classes are specialized data storage and retrieval classes. Stacks, queues, lists, and hash tables are all supported by these classes. The interfaces of most collection classes are the same.
Collection classes perform various functions, such as dynamically allocating memory to elements and accessing a list of objects by an index. These classes generate objects from the Object class, which serves as the foundation for all data types in VB.Net.
Collection Classes and their usage
The System.Collection namespace most commonly used classes are listed below:
Class |
Description and Usage |
It represents an ordered collection of objects that may be individually indexed. It is essentially an array substitute. However, unlike arrays, you can add and remove items from a list at a specific point using an index, and the array automatically resizes itself. It also supports dynamic memory allocation and the addition, search, and sorting of objects in a list. |
|
It makes use of a key to gain access to the objects in the collection. You utilise a hash table when you need to access elements by key and can determine a reasonable key value. Each hash table item has a key/value pair. The key is used to gain access to the collection's items. |
|
To access the items in a list, it employs both a key and an index. A sorted list combines an array with a hash table. It comprises a list of objects that can be accessed when you pass parameters by reference key or an index. If you access things by index, it's an ArrayList; if you access items by key, it's a Hashtable. The key value is always used to sort the collection of items. |
|
It represents a group of objects arranged in a last-in, first-out order. It is utilized when objects must be accessed last-in-first-out. When you add an item to the list, this is referred to as pushing the item, and when you remove it, this is referred to as popping the item. |
|
It symbolizes a collection of objects arranged in a first-in, first-out order. It is utilized when objects must be accessed first-in-first-out. When you add an item to the list, it is referred to as enqueue, and when you delete an item, it is referred to as deque. |
|
It depicts a binary representation array with the values 1 and 0. It is used when you need to store bits but don't know how much you'll need ahead of time. Items in the BitArray collection can be accessed by using an integer index that begins with zero. |