Define arrays and collections.
Arrays:- It stores a fixed size sequential collection of elements of the same type.
- It is used to store a collection of data.
- It consists of contiguous memory locations.
- The lowest element corresponds to the first and the highest element to the last.
- It provides best performance for certain requirements.
Example:1. Dim a() As Integer = {5, 10, 15, 20} // Initializing array : An array of 5 element
2. String name(5) As String // An array of 6 strings
Collections:- A collection can also store group of objects. But unlike an array which is of fixed length, the collection can grow or shrink dynamically.
- Items can be added or removed at run time.
- These are the specialized classes for data storage and retrieval.
- It supports stack, queues, lists and hash tables.
Collection includes various classes are as follows:Class | Description |
ArrayList | It represents ordered collection of an object that can be indexed individually. |
Hashtable | It uses a key to access the elements in the collection. |
StoredList | It uses a key as well as an index to access the items in a list. |
Stack | It represents LIFO(Last-In-First-Out) collection of object. |
Queue | It represents FIFO(First-In-First-Out) collection of object. |