Click Here to View Practical Example
Types of Collections:
1. ArrayList
2. Stack
3. Queue
4. Hashtable
5. SortedList
Types of Collections:
1. ArrayList
2. Stack
3. Queue
4. Hashtable
5. SortedList
- ArrayList can store elements of any data type. Like array, we don't need to specify the size of ArrayList at the time of it declaration. ArrayList collection class provide you to dynamically add or remove items from array. You can use ArrayList instead of array when you don't know the how many items will inserted. ArrayList is more used when all items are different data type.
- Stack is a kind of collection that can useful when you need to store data in a specific order for sequential processing. A Stack works on principle of LIFO - Last In First Out, which means that last item inserted into the stack will be the first item to be removed from stack.The adding of an item into stack is known as Push operation, removing an item from stack is known as Pop operation and if an item only read from top of stack is known as Peek operation.
- Similar to Stack, Queue can useful when you need to store data in a specific order for sequential processing.A Queue works on the principle of FIFO - First In First Out, which means that the first item inserted into Queue will be first remove form Queue.The adding of an item into queue is known as Enqueue operation, removing an item from queue is known as Dequeue operation and if an item only read from top of queue is known as Peek operation.
- HashTable stores any data type of items as key-value pairs. The data is stored in Hashtable basis of key and can be accessed by the key rather than index of items.Each items in the HashTable in uniquely identified by it's key.
- A SortedList is a collection that contains key-value pairs. The data is stored in SortedList basis of key and it can be accessed by the key or the index and because of it is sorted.